summaryrefslogtreecommitdiff
path: root/src/tests/tng_parallel_read.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/tng_parallel_read.c')
-rw-r--r--src/tests/tng_parallel_read.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/src/tests/tng_parallel_read.c b/src/tests/tng_parallel_read.c
index d0aaa15..824fc73 100644
--- a/src/tests/tng_parallel_read.c
+++ b/src/tests/tng_parallel_read.c
@@ -21,7 +21,7 @@
/* N.B. this code is for testing parallel reading of trajectory frame sets. The
* performance is not improved very much and is to a large extent limited by
* disk i/o. It can however be used as inspiration for writing parallel code
- * using the TNG library. */
+ * using the TNG library. The code is NOT fully tested and may behave strangely. */
int main(int argc, char **argv)
{
@@ -29,9 +29,9 @@ int main(int argc, char **argv)
union data_values ***local_positions = 0; // A 3-dimensional array to be populated
union data_values **particle_pos = 0;
int64_t n_particles, n_values_per_frame, n_frame_sets, n_frames;
- int64_t n_frames_per_frame_set;
+ int64_t n_frames_per_frame_set, tot_n_frames = 0;
char data_type;
- int i, j;
+ int i, j, fail;
int64_t particle = 0, local_first_frame, local_last_frame;
char atom_name[64], res_name[64];
tng_trajectory_frame_set_t frame_set = 0;
@@ -66,7 +66,7 @@ int main(int argc, char **argv)
tng_num_frame_sets_get(traj, &n_frame_sets);
tng_num_frames_per_frame_set_get(traj, &n_frames_per_frame_set);
- particle_pos = malloc(sizeof(union data_values **) * n_frame_sets *
+ particle_pos = malloc(sizeof(union data_values *) * n_frame_sets *
n_frames_per_frame_set);
for(i = n_frame_sets * n_frames_per_frame_set; i--;)
{
@@ -89,12 +89,14 @@ int main(int argc, char **argv)
{
printf("Particle name not found\n");
}
+
+ fail = 0;
#pragma omp parallel \
private (n_frames, n_particles, n_values_per_frame, \
- local_first_frame, local_last_frame, j) \
+ local_first_frame, local_last_frame, j, fail) \
firstprivate (local_traj, local_positions, frame_set)\
-shared(data_type, traj, n_frame_sets, particle_pos, particle, i)\
+shared(data_type, traj, n_frame_sets, particle_pos, particle, i, tot_n_frames)\
default(none)
{
/* Each tng_trajectory_t keeps its own file pointers and i/o positions.
@@ -106,22 +108,30 @@ default(none)
if(tng_frame_set_nr_find(local_traj, i) != TNG_SUCCESS)
{
printf("FAILED finding frame set %d!\n", i);
+ tot_n_frames = 0;
+ fail = 1;
}
if(tng_particle_data_get(local_traj, TNG_TRAJ_POSITIONS, &local_positions,
&n_frames, &n_particles, &n_values_per_frame,
&data_type) != TNG_SUCCESS)
{
printf("FAILED getting particle data\n");
+ tot_n_frames = 0;
+ fail = 1;
}
- tng_current_frame_set_get(local_traj, &frame_set);
- tng_frame_set_frame_range_get(local_traj, frame_set, &local_first_frame, &local_last_frame);
-// printf("Frame %"PRId64"-%"PRId64":\n", local_first_frame, local_last_frame);
-// printf("%"PRId64" %"PRId64" %"PRId64"\n", n_frames, n_particles, n_values_per_frame);
- for(j = 0; j < n_frames; j++)
+ if(!fail)
{
- particle_pos[local_first_frame + j][0] = local_positions[j][particle][0];
- particle_pos[local_first_frame + j][1] = local_positions[j][particle][1];
- particle_pos[local_first_frame + j][2] = local_positions[j][particle][2];
+ tng_current_frame_set_get(local_traj, &frame_set);
+ tng_frame_set_frame_range_get(local_traj, frame_set, &local_first_frame, &local_last_frame);
+ // printf("Frame %"PRId64"-%"PRId64":\n", local_first_frame, local_last_frame);
+ // printf("%"PRId64" %"PRId64" %"PRId64"\n", n_frames, n_particles, n_values_per_frame);
+ tot_n_frames += n_frames;
+ for(j = 0; j < n_frames; j++)
+ {
+ particle_pos[local_first_frame + j][0] = local_positions[j][particle][0];
+ particle_pos[local_first_frame + j][1] = local_positions[j][particle][1];
+ particle_pos[local_first_frame + j][2] = local_positions[j][particle][2];
+ }
}
}
@@ -136,24 +146,24 @@ default(none)
switch(data_type)
{
case TNG_INT_DATA:
- for(i = 0; i < n_frame_sets * n_frames_per_frame_set; i++)
+ for(j = 0; j < tot_n_frames; j++)
{
- printf("\t%"PRId64"\t%"PRId64"\t%"PRId64"\n", particle_pos[i][0].i,
- particle_pos[i][1].i, particle_pos[i][2].i);
+ printf("\t%"PRId64"\t%"PRId64"\t%"PRId64"\n", particle_pos[j][0].i,
+ particle_pos[j][1].i, particle_pos[j][2].i);
}
break;
case TNG_FLOAT_DATA:
- for(i = 0; i < n_frame_sets * n_frames_per_frame_set; i++)
+ for(j = 0; j < tot_n_frames; j++)
{
- printf("\t%f\t%f\t%f\n", particle_pos[i][0].f,
- particle_pos[i][1].f, particle_pos[i][2].f);
+ printf("\t%f\t%f\t%f\n", particle_pos[j][0].f,
+ particle_pos[j][1].f, particle_pos[j][2].f);
}
break;
case TNG_DOUBLE_DATA:
- for(i = 0; i < n_frame_sets * n_frames_per_frame_set; i++)
+ for(j = 0; j < tot_n_frames; j++)
{
- printf("\t%f\t%f\t%f\n", particle_pos[i][0].d,
- particle_pos[i][1].d, particle_pos[i][2].d);
+ printf("\t%f\t%f\t%f\n", particle_pos[j][0].d,
+ particle_pos[j][1].d, particle_pos[j][2].d);
}
break;
default:
contact: Jan Huwald // Impressum