Skip to content

Commit

Permalink
Update code, reduce compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
houjun committed Jan 17, 2025
1 parent b96a78e commit 9038ad2
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 146 deletions.
47 changes: 21 additions & 26 deletions examples/bdcatsio_batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ read_h5_data(int rank, hid_t loc, hid_t *dset_ids, hid_t filespace, hid_t memspa
void
print_usage(char *name)
{
printf("Usage: %s /path/to/file #timestep sleep_sec [# mega particles]\n", name);
printf("Usage: %s /path/to/file #mega_particles #timestep sleep_sec \n", name);
}

int
Expand All @@ -133,41 +133,38 @@ main(int argc, char *argv[])
char *file_name;

MPI_Init(&argc, &argv);
if (argc < 3) {
printf("Usage: ./%s /path/to/file #timestep [# mega particles]\n", argv[0]);
return 0;
}
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);

if (argc < 4) {
if (argc < 3) {
print_usage(argv[0]);
return 0;
}

file_name = argv[1];

nts = atoi(argv[2]);
if (argc >= 3)
numparticles = (atoi(argv[2])) * 1024 * 1024;
else
numparticles = 8 * 1024 * 1024;


nts = atoi(argv[3]);
if (nts <= 0) {
printf("Usage: ./%s /path/to/file #timestep [# mega particles]\n", argv[0]);
print_usage(argv[0]);
return 0;
}

sleep_time = atoi(argv[3]);
sleep_time = atoi(argv[4]);
if (sleep_time < 0) {
print_usage(argv[0]);
return 0;
}

if (argc == 5) {
numparticles = (atoi(argv[4])) * 1024 * 1024;
}
else {
numparticles = 8 * 1024 * 1024;
}

if (my_rank == 0) {
printf("Number of paritcles: %ld \n", numparticles);
fprintf(stderr, "Number of paritcles: %ld \n", numparticles);
fprintf(stderr, "Number of steps: %d \n", nts);
fprintf(stderr, "Sleep time: %d \n", sleep_time);
}

x = (float *)malloc(numparticles * sizeof(double));
Expand Down Expand Up @@ -219,7 +216,6 @@ main(int argc, char *argv[])
dset_ids[i] = (hid_t *)calloc(8, sizeof(hid_t));

MPI_Barrier(MPI_COMM_WORLD);
timer_on(1);

for (i = 0; i < nts; i++) {

Expand All @@ -229,30 +225,29 @@ main(int argc, char *argv[])
if (my_rank == 0)
printf("Read %s ... \n", grp_name);

timer_on(1);
timer_reset(2);
timer_on(2);

read_h5_data(my_rank, grp_ids[i], dset_ids[i], filespace, memspace, dxpl);

MPI_Barrier(MPI_COMM_WORLD);
timer_off(1);
timer_off(2);
if (my_rank == 0)
timer_msg(2, "read 1 step");

if (i != 0) {
for (j = 0; j < 8; j++)
H5Dclose(dset_ids[i][j]);
H5Gclose(grp_ids[i]);

if (i != nts - 1) {
if (my_rank == 0)
printf(" sleep for %ds\n", sleep_time);
sleep(sleep_time);
}

for (j = 0; j < 8; j++)
H5Dclose(dset_ids[i][j]);
H5Gclose(grp_ids[i]);
}

MPI_Barrier(MPI_COMM_WORLD);
timer_off(1);

H5Sclose(memspace);
H5Sclose(filespace);
H5Pclose(fapl);
Expand Down
36 changes: 16 additions & 20 deletions examples/vpicio_batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <unistd.h>

herr_t ierr;
hid_t file_id, dset_id, fapl;
hid_t file_id, dset_id, grp_id, fapl;
hid_t filespace, memspace;
hid_t plist_id, dcpl_id;

Expand Down Expand Up @@ -49,25 +49,16 @@ init_particles()
}

void
create_h5_datasets(int i)
create_h5_datasets()
{
char dname[128];
sprintf(dname, "step%d_x", i);
dsets[0] = H5Dcreate(file_id, dname, H5T_NATIVE_FLOAT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
sprintf(dname, "step%d_y", i);
dsets[1] = H5Dcreate(file_id, dname, H5T_NATIVE_FLOAT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
sprintf(dname, "step%d_z", i);
dsets[2] = H5Dcreate(file_id, dname, H5T_NATIVE_FLOAT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
sprintf(dname, "step%d_id1", i);
dsets[3] = H5Dcreate(file_id, dname, H5T_NATIVE_INT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
sprintf(dname, "step%d_id2", i);
dsets[4] = H5Dcreate(file_id, dname, H5T_NATIVE_INT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
sprintf(dname, "step%d_px", i);
dsets[5] = H5Dcreate(file_id, dname, H5T_NATIVE_FLOAT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
sprintf(dname, "step%d_py", i);
dsets[6] = H5Dcreate(file_id, dname, H5T_NATIVE_FLOAT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
sprintf(dname, "step%d_pz", i);
dsets[7] = H5Dcreate(file_id, dname, H5T_NATIVE_FLOAT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
dsets[0] = H5Dcreate(grp_id, "x", H5T_NATIVE_FLOAT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
dsets[1] = H5Dcreate(grp_id, "y", H5T_NATIVE_FLOAT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
dsets[2] = H5Dcreate(grp_id, "z", H5T_NATIVE_FLOAT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
dsets[3] = H5Dcreate(grp_id, "id1", H5T_NATIVE_INT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
dsets[4] = H5Dcreate(grp_id, "id2", H5T_NATIVE_INT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
dsets[5] = H5Dcreate(grp_id, "px", H5T_NATIVE_FLOAT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
dsets[6] = H5Dcreate(grp_id, "py", H5T_NATIVE_FLOAT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
dsets[7] = H5Dcreate(grp_id, "pz", H5T_NATIVE_FLOAT, filespace, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
}

void
Expand Down Expand Up @@ -165,6 +156,7 @@ main(int argc, char *argv[])
int my_rank, num_procs, nstep, i, sleeptime;
MPI_Comm comm = MPI_COMM_WORLD;
double t0, t1, t2, t3, tw = 0;
char grp_name[128];

MPI_Init(&argc, &argv);
MPI_Comm_rank(comm, &my_rank);
Expand Down Expand Up @@ -243,9 +235,11 @@ main(int argc, char *argv[])
printf("Created HDF5 file [%s] \n", argv[1]);

for (i = 0; i < nstep; i++) {
sprintf(grp_name, "Timestep_%d", i);
grp_id = H5Gcreate(file_id, grp_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

filespace = H5Screate_simple(1, (hsize_t *)&total_particles, NULL);
create_h5_datasets(i);
create_h5_datasets();

H5Sselect_hyperslab(filespace, H5S_SELECT_SET, (hsize_t *)&offset, NULL, (hsize_t *)&numparticles,
NULL);
Expand All @@ -262,6 +256,8 @@ main(int argc, char *argv[])
tw += (t2 - t1);

close_h5_datasets();

H5Gclose(grp_id);
H5Sclose(filespace);

if (my_rank == 0)
Expand Down
Loading

0 comments on commit 9038ad2

Please sign in to comment.