summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/tng_io_testing.c38
-rw-r--r--src/tests/tng_parallel_read.c31
2 files changed, 37 insertions, 32 deletions
diff --git a/src/tests/tng_io_testing.c b/src/tests/tng_io_testing.c
index 96b53f7..0f67ccc 100644
--- a/src/tests/tng_io_testing.c
+++ b/src/tests/tng_io_testing.c
@@ -136,7 +136,7 @@ static tng_function_status tng_test_read_and_write_file
}
stat = tng_frame_set_write(traj, TNG_USE_HASH);
}
-
+
return(stat);
}
@@ -148,11 +148,11 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj)
int64_t frame_nr;
double box_shape[9];
char atom_type[16], annotation[128];
- tng_function_status stat;
+ tng_function_status stat = TNG_SUCCESS;
tng_medium_stride_length_set(traj, 10);
tng_long_stride_length_set(traj, 100);
-
+
/* Create molecules */
if(tng_test_setup_molecules(traj) == TNG_CRITICAL)
{
@@ -200,7 +200,7 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj)
printf("Failed setting partial charges.\n");
return(TNG_CRITICAL);
}
-
+
stat = tng_particle_data_block_add(traj, TNG_TRAJ_PARTIAL_CHARGES, "PARTIAL CHARGES",
TNG_FLOAT_DATA, TNG_NON_TRAJECTORY_BLOCK,
1, 1, 1, 0, n_particles,
@@ -230,9 +230,9 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj)
printf("Cannot write file headers.\n");
}
-
+
tng_num_frames_per_frame_set_get(traj, &n_frames_per_frame_set);
-
+
data = malloc(sizeof(float) * n_particles *
n_frames_per_frame_set * 3);
if(!data)
@@ -366,9 +366,9 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj)
return(TNG_CRITICAL);
}
}
-
+
/* Write two more frame sets one frame at a time */
- cnt = 0;
+
/* Make a new frame set - if always using the same mapping blocks
* it is not necessary to explicitly add a new frame set - it will
* be added automatically when adding data for a frame */
@@ -383,7 +383,7 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj)
}
frame_nr = i * n_frames_per_frame_set;
-
+
for(k=0; k<300; k++)
{
mapping[k]=k;
@@ -470,7 +470,7 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj)
}
}
}
-
+
free(molpos);
free(data);
@@ -481,7 +481,7 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj)
#endif
stat = tng_file_headers_read(traj, TNG_SKIP_HASH);
-
+
while(stat == TNG_SUCCESS)
{
stat = tng_frame_set_read_next(traj, TNG_SKIP_HASH);
@@ -582,7 +582,7 @@ int main()
tng_trajectory_t traj;
tng_function_status stat;
char time_str[TNG_MAX_DATE_STR_LEN];
-
+
if(tng_trajectory_init(&traj) != TNG_SUCCESS)
{
tng_trajectory_destroy(&traj);
@@ -614,7 +614,7 @@ int main()
{
printf("Test Read and write file:\t\t\tSucceeded.\n");
}
-
+
if(tng_test_get_box_data(traj) != TNG_SUCCESS)
{
printf("Test Get data:\t\t\t\t\tFailed. %s: %d\n",
@@ -635,7 +635,7 @@ int main()
{
printf("Test Destroy and init trajectory:\t\tSucceeded.\n");
}
-
+
#ifdef EXAMPLE_FILES_DIR
tng_output_file_set(traj, EXAMPLE_FILES_DIR "tng_test.tng");
@@ -652,7 +652,7 @@ int main()
{
printf("Test Write and read file:\t\t\tSucceeded.\n");
}
-
+
if(tng_test_get_positions_data(traj) != TNG_SUCCESS)
{
printf("Test Get particle data:\t\t\t\tFailed. %s: %d\n",
@@ -674,7 +674,7 @@ int main()
printf("Test Destroy trajectory:\t\t\tSucceeded.\n");
}
-
+
#ifdef EXAMPLE_FILES_DIR
stat = tng_util_trajectory_open(EXAMPLE_FILES_DIR "tng_test.tng", 'r', &traj);
#else
@@ -691,7 +691,7 @@ int main()
printf("Test Utility function open:\t\t\tSucceeded.\n");
}
- stat = tng_util_trajectory_close(&traj);
+ stat = tng_util_trajectory_close(&traj);
if(stat != TNG_SUCCESS)
{
printf("Test Utility function close:\t\t\tFailed. %s: %d.\n",
@@ -702,8 +702,8 @@ int main()
{
printf("Test Utility function close:\t\t\tSucceeded.\n");
}
-
+
printf("Tests finished\n");
-
+
exit(0);
} \ No newline at end of file
diff --git a/src/tests/tng_parallel_read.c b/src/tests/tng_parallel_read.c
index d0aaa15..58863b0 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,7 +29,7 @@ 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;
int64_t particle = 0, local_first_frame, local_last_frame;
@@ -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--;)
{
@@ -94,7 +94,7 @@ int main(int argc, char **argv)
private (n_frames, n_particles, n_values_per_frame, \
local_first_frame, local_last_frame, j) \
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,17 +106,22 @@ 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;
+ break;
}
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;
+ break;
}
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];
@@ -136,24 +141,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