@@ -19,9 +19,9 @@ uniform_random_number()
1919int
2020main (int argc , char * argv [])
2121{
22- hid_t file_id , group_id , fapl_id , lcpl , gcpl ;
22+ hid_t file_id , group_id , fapl_id , dxpl_id ;
2323 hid_t dset_id1 , dset_id2 , dset_id3 , dset_id4 , dset_id5 , dset_id6 , dset_id7 , dset_id8 ;
24- hid_t r_dset_id1 , r_dset_id2 , r_dset_id3 , r_dset_id4 , r_dset_id5 , r_dset_id6 , r_dset_id7 , r_dset_id8 ;
24+ hid_t r_dset_id1 , r_dset_id2 ;
2525 hid_t filespace , memspace ;
2626 hid_t attr1 ;
2727 hid_t aid1 ;
@@ -34,24 +34,18 @@ main(int argc, char *argv[])
3434 my_rank = 0 ;
3535 num_procs = 1 ;
3636 // Variables and dimensions
37- // long numparticles = 8388608; // 8 meg particles per process
38- long numparticles = 4 ;
37+ long numparticles = 8388608 ; // 8 meg particles per process
38+ /* long numparticles = 4; */
3939 long long total_particles , offset ;
4040
4141 float * x , * y , * z ;
42- float * xr ;
4342 float * px , * py , * pz ;
4443 int * id1 , * id2 ;
4544 int x_dim = 64 ;
4645 int y_dim = 64 ;
4746 int z_dim = 64 ;
48- int i , j ;
49-
50- float matrix [ADIM1 ][ADIM2 ]; /* Attribute data */
51- for (i = 0 ; i < ADIM1 ; i ++ ) { /* Values of the array attribute */
52- for (j = 0 ; j < ADIM2 ; j ++ )
53- matrix [i ][j ] = -1. ;
54- }
47+ int i ;
48+ double stime , etime ;
5549
5650 MPI_Init (& argc , & argv );
5751 MPI_Comm_dup (MPI_COMM_WORLD , & comm );
@@ -66,16 +60,12 @@ main(int argc, char *argv[])
6660 if (my_rank == 0 )
6761 printf ("Number of paritcles: %ld \n" , numparticles );
6862
69- x = (float * )malloc (numparticles * sizeof (float ));
70- y = (float * )malloc (numparticles * sizeof (float ));
71- z = (float * )malloc (numparticles * sizeof (float ));
72-
73- xr = (float * )malloc (numparticles * sizeof (float ));
74-
75- px = (float * )malloc (numparticles * sizeof (float ));
76- py = (float * )malloc (numparticles * sizeof (float ));
77- pz = (float * )malloc (numparticles * sizeof (float ));
78-
63+ x = (float * )malloc (numparticles * sizeof (float ));
64+ y = (float * )malloc (numparticles * sizeof (float ));
65+ z = (float * )malloc (numparticles * sizeof (float ));
66+ px = (float * )malloc (numparticles * sizeof (float ));
67+ py = (float * )malloc (numparticles * sizeof (float ));
68+ pz = (float * )malloc (numparticles * sizeof (float ));
7969 id1 = (int * )malloc (numparticles * sizeof (int ));
8070 id2 = (int * )malloc (numparticles * sizeof (int ));
8171
@@ -95,24 +85,18 @@ main(int argc, char *argv[])
9585 printf ("H5Pcreate() error\n" );
9686 H5Pset_fapl_mpio (fapl_id , MPI_COMM_WORLD , MPI_INFO_NULL );
9787
98- /* Initialize VOL */
99- // pdc_vol_id = H5VLregister_connector_by_name("pdc", H5P_DEFAULT); // not used if choosing to use
100- // environmental variable
88+ memspace = H5Screate_simple (1 , (hsize_t * )& numparticles , NULL );
89+ filespace = H5Screate_simple (1 , (hsize_t * )& total_particles , NULL );
90+
91+ MPI_Barrier (MPI_COMM_WORLD );
92+ stime = MPI_Wtime ();
10193
10294 /* Create file */
10395 if ((file_id = H5Fcreate (argv [1 ], H5F_ACC_TRUNC , H5P_DEFAULT , fapl_id )) < 0 )
10496 printf ("H5Fcreate() error\n" );
10597
106- memspace = H5Screate_simple (1 , (hsize_t * )& numparticles , NULL );
107- filespace = H5Screate_simple (1 , (hsize_t * )& total_particles , NULL );
108-
109- if ((lcpl = H5Pcreate (H5P_LINK_CREATE )) < 0 )
110- printf ("lcpl H5Pcreate() error\n" );
111- if ((gcpl = H5Pcreate (H5P_GROUP_CREATE )) < 0 )
112- printf ("gcpl H5Pcreate() error\n" );
113-
11498 /* Create group */
115- if ((group_id = H5Gcreate2 (file_id , "group1" , lcpl , gcpl , H5P_DEFAULT )) < 0 )
99+ if ((group_id = H5Gcreate2 (file_id , "group1" , H5P_DEFAULT , H5P_DEFAULT , H5P_DEFAULT )) < 0 )
116100 printf ("H5Gcreate() error\n" );
117101
118102 /* Create dataset */
@@ -125,64 +109,79 @@ main(int argc, char *argv[])
125109 dset_id7 = H5Dcreate (file_id , "id1" , H5T_NATIVE_INT , filespace , H5P_DEFAULT , H5P_DEFAULT , H5P_DEFAULT );
126110 dset_id8 = H5Dcreate (file_id , "id2" , H5T_NATIVE_INT , filespace , H5P_DEFAULT , H5P_DEFAULT , H5P_DEFAULT );
127111
128- fapl_id = H5Pcreate (H5P_DATASET_XFER );
129- H5Pset_dxpl_mpio (fapl_id , H5FD_MPIO_COLLECTIVE );
112+ MPI_Barrier (MPI_COMM_WORLD );
113+ etime = MPI_Wtime ();
114+ if (my_rank == 0 )
115+ printf ("File/Group/Dataset create took %.2f seconds\n" , etime - stime );
116+
117+ dxpl_id = H5Pcreate (H5P_DATASET_XFER );
118+ H5Pset_dxpl_mpio (dxpl_id , H5FD_MPIO_COLLECTIVE );
130119 H5Sselect_hyperslab (filespace , H5S_SELECT_SET , (hsize_t * )& offset , NULL , (hsize_t * )& numparticles , NULL );
131120
132121 MPI_Barrier (comm );
133- ierr = H5Dwrite (dset_id1 , H5T_NATIVE_FLOAT , memspace , filespace , fapl_id , x );
122+ stime = MPI_Wtime ();
123+
124+ ierr = H5Dwrite (dset_id1 , H5T_NATIVE_FLOAT , memspace , filespace , dxpl_id , x );
134125 if (ierr < 0 )
135126 printf ("write x failed\n" );
136- ierr = H5Dwrite (dset_id2 , H5T_NATIVE_FLOAT , memspace , filespace , fapl_id , y );
127+ ierr = H5Dwrite (dset_id2 , H5T_NATIVE_FLOAT , memspace , filespace , dxpl_id , y );
137128 if (ierr < 0 )
138129 printf ("write y failed\n" );
139- ierr = H5Dwrite (dset_id3 , H5T_NATIVE_FLOAT , memspace , filespace , fapl_id , z );
130+ ierr = H5Dwrite (dset_id3 , H5T_NATIVE_FLOAT , memspace , filespace , dxpl_id , z );
140131 if (ierr < 0 )
141132 printf ("write z failed\n" );
142- ierr = H5Dwrite (dset_id4 , H5T_NATIVE_FLOAT , memspace , filespace , fapl_id , px );
133+ ierr = H5Dwrite (dset_id4 , H5T_NATIVE_FLOAT , memspace , filespace , dxpl_id , px );
143134 if (ierr < 0 )
144135 printf ("write px failed\n" );
145- ierr = H5Dwrite (dset_id5 , H5T_NATIVE_FLOAT , memspace , filespace , fapl_id , py );
136+ ierr = H5Dwrite (dset_id5 , H5T_NATIVE_FLOAT , memspace , filespace , dxpl_id , py );
146137 if (ierr < 0 )
147138 printf ("write py failed\n" );
148- ierr = H5Dwrite (dset_id6 , H5T_NATIVE_FLOAT , memspace , filespace , fapl_id , pz );
139+ ierr = H5Dwrite (dset_id6 , H5T_NATIVE_FLOAT , memspace , filespace , dxpl_id , pz );
149140 if (ierr < 0 )
150141 printf ("write pz failed\n" );
151- ierr = H5Dwrite (dset_id7 , H5T_NATIVE_INT , memspace , filespace , fapl_id , id1 );
142+ ierr = H5Dwrite (dset_id7 , H5T_NATIVE_INT , memspace , filespace , dxpl_id , id1 );
152143 if (ierr < 0 )
153144 printf ("write id1 failed\n" );
154- ierr = H5Dwrite (dset_id8 , H5T_NATIVE_INT , memspace , filespace , fapl_id , id2 );
145+ ierr = H5Dwrite (dset_id8 , H5T_NATIVE_INT , memspace , filespace , dxpl_id , id2 );
155146 if (ierr < 0 )
156147 printf ("write id2 failed\n" );
157148
158- r_dset_id1 = H5Dopen2 (file_id , "x" , H5P_DEFAULT );
159- // r_dset_id2 = H5Dopen2(file_id, "y", H5P_DEFAULT);
160- // r_dset_id3 = H5Dopen2(file_id, "z", H5P_DEFAULT);
161- // r_dset_id4 = H5Dopen2(file_id, "px", H5P_DEFAULT);
162- // r_dset_id5 = H5Dopen2(file_id, "py", H5P_DEFAULT);
163- // r_dset_id6 = H5Dopen2(file_id, "pz", H5P_DEFAULT);
164- // r_dset_id7 = H5Dopen2(file_id, "id1", H5P_DEFAULT);
165- // r_dset_id8 = H5Dopen2(file_id, "id2", H5P_DEFAULT);
149+ MPI_Barrier (MPI_COMM_WORLD );
150+ etime = MPI_Wtime ();
151+ if (my_rank == 0 )
152+ printf ("Dataset write took %.2f seconds\n" , etime - stime );
153+
154+ r_dset_id1 = H5Dopen2 (file_id , "id1" , H5P_DEFAULT );
155+ r_dset_id2 = H5Dopen2 (file_id , "id2" , H5P_DEFAULT );
166156
167- ierr = H5Dread (dset_id1 , H5T_NATIVE_FLOAT , memspace , filespace , fapl_id , xr );
157+ ierr = H5Dread (r_dset_id1 , H5T_NATIVE_INT , memspace , filespace , dxpl_id , id1 );
168158 if (ierr < 0 )
169159 printf ("read dset1 failed\n" );
170160
171- fprintf (stderr , "\nxr vals:\n" );
161+ ierr = H5Dread (r_dset_id2 , H5T_NATIVE_INT , memspace , filespace , dxpl_id , id2 );
162+ if (ierr < 0 )
163+ printf ("read r_dset2 failed\n" );
164+
165+ if (H5Dclose (r_dset_id1 ) < 0 )
166+ printf ("H5Dclose dataset1 error\n" );
167+
168+ if (H5Dclose (r_dset_id2 ) < 0 )
169+ printf ("H5Dclose dataset2 error\n" );
170+
172171 for (loop = 0 ; loop < numparticles ; loop ++ ) {
173- fprintf (stderr , "%f " , xr [loop ]);
172+ if (id1 [loop ] != loop ) {
173+ fprintf (stderr , "Error id1: %d / %d\n" , id1 [loop ], loop );
174+ break ;
175+ }
174176 }
175- fprintf ( stderr , "\nx vals:\n" );
177+
176178 for (loop = 0 ; loop < numparticles ; loop ++ ) {
177- fprintf (stderr , "%f " , x [loop ]);
179+ if (id2 [loop ] != loop * 2 ) {
180+ fprintf (stderr , "Error id2: %d / %d\n" , id2 [loop ], loop * 2 );
181+ break ;
182+ }
178183 }
179184
180- ierr = H5Dread (r_dset_id1 , H5T_NATIVE_FLOAT , memspace , filespace , fapl_id , xr );
181- if (ierr < 0 )
182- printf ("read r_dset1 failed\n" );
183- if (H5Dclose (r_dset_id1 ) < 0 )
184- printf ("H5Dclose dataset8 error\n" );
185-
186185 /* create attribute */
187186 aid1 = H5Screate (H5S_SCALAR );
188187 attr1 = H5Acreate2 (dset_id1 , "Integer attribute" , H5T_NATIVE_INT , aid1 , H5P_DEFAULT , H5P_DEFAULT );
@@ -234,9 +233,7 @@ main(int argc, char *argv[])
234233 printf ("H5Fclose error\n" );
235234 if (H5Pclose (fapl_id ) < 0 )
236235 printf ("H5Pclose error\n" );
237- if (H5Pclose (lcpl ) < 0 )
238- printf ("H5Pclose error\n" );
239- if (H5Pclose (gcpl ) < 0 )
236+ if (H5Pclose (dxpl_id ) < 0 )
240237 printf ("H5Pclose error\n" );
241238
242239 if (my_rank == 0 ) {
@@ -252,7 +249,6 @@ main(int argc, char *argv[])
252249 free (id1 );
253250 free (id2 );
254251
255- free (xr );
256- (void )MPI_Finalize ();
252+ MPI_Finalize ();
257253 return 0 ;
258254}
0 commit comments