src/hdf5/H5ecloud/H5ParallelTest.cc

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <hdf5.h>
00005 #include "H5Part.hh"
00006 
00007 #ifdef READTEST
00008 
00009 #endif
00010 
00011 #ifdef REGRESSIONTEST
00012 
00013 /*
00014   A simple regression test that shows how you use this API
00015   to write and read multi-timestep files of particle data.
00016 */
00017 #ifdef PARALLEL_IO
00018 
00019 int main(int argc,char *argv[]){
00020   int sz=5;
00021   double *x,*y,*z;
00022   long long *id;
00023   char name[64];
00024   H5PartFile *file;
00025   int i,t,nt,nds;
00026   int nprocs,myproc;
00027   hid_t gid;
00028   MPI_Comm comm=MPI_COMM_WORLD;
00029 
00030   MPI_Init(&argc,&argv);
00031   MPI_Comm_size(comm,&nprocs);
00032   MPI_Comm_rank(comm,&myproc);
00033 
00034   x=(double*)malloc(sz*nprocs*sizeof(double));
00035   y=(double*)malloc(sz*nprocs*sizeof(double));
00036   z=(double*)malloc(sz*nprocs*sizeof(double));
00037   id=(long long*)malloc(sz*nprocs*sizeof(long long));
00038   /* parallel file creation */
00039   file=H5PartOpenFileParallel("parttest.h5",H5PART_WRITE,comm);
00040   if(!file) {
00041     perror("File open failed:  exiting!");
00042     exit(0);
00043   }
00044 
00045   for(t=0;t<5;t++){
00046     MPI_Barrier(comm);
00047     for(i=0;i<sz;i++) {
00048       x[i]=(double)(i+t)+10.0*(double)myproc;
00049       y[i]=0.1 + (double)(i+t);
00050       z[i]=0.2 + (double)(i+t*10);
00051       id[i]=i+sz*myproc;
00052     }
00053     printf("Proc[%u] Writing timestep %u file=%u\n",myproc,t,file->file);
00054     H5PartSetStep(file,t); /* must set the current timestep in file */
00055     H5PartSetNumParticles(file,sz); /* then set number of particles to store */
00056     /* now write different tuples of data into this timestep of the file */
00057     H5PartWriteDataFloat64(file,"x",x); 
00058     H5PartWriteDataFloat64(file,"y",y);
00059     H5PartWriteDataFloat64(file,"z",z);
00060 
00061     H5PartWriteDataFloat64(file,"px",x); 
00062     H5PartWriteDataFloat64(file,"py",y);
00063     H5PartWriteDataFloat64(file,"pz",z);
00064 
00065     H5PartWriteDataInt64(file,"id",id);
00066   }
00067 
00068   unsigned int idStart = 0+sz*myproc;
00069   unsigned int idEnd = (sz-1)+sz*myproc;
00070 
00071   printf("AllDone p[%u]\n",myproc);
00072   H5PartCloseFile(file);
00073   MPI_Barrier(comm);
00074   
00075   printf("p[%u:%u] : OK, close file and reopen for reading idStart %u  idEnd %u \n",myproc,nprocs,idStart,idEnd);
00076 
00077   file=H5PartOpenFileParallel("parttest.h5",H5PART_READ,comm);
00078   H5PartSetStep(file,0);
00079   unsigned int np = 0;
00080   // unsigned int np = (int)H5PartGetNumParticles(file);
00081   // nt=H5PartGetNumSteps(file); /* get number of steps in file */
00082   
00083   //nds=H5PartGetNumDatasets(file); /* get number of datasets in timestep 0 */
00084   MPI_Barrier(comm);
00085   
00086   //  H5PartSetView(file,idStart,idEnd);
00087 
00088   printf("steps= %u  datasets= %u particles= %u\n",nt,nds,np);
00089 
00090   if(x) 
00091     free(x); 
00092   if(y) 
00093     free(y);
00094   if(z) 
00095     free(z);
00096   if(id) 
00097     free(id);
00098 
00099   H5PartCloseFile(file);
00100   MPI_Barrier(comm);
00101   fprintf(stderr,"proc[%u]:  done\n",myproc);
00102   return MPI_Finalize();
00103 }
00104 
00105 #else
00106 
00107 #endif
00108 
00109 #endif
00110 
00111 

Generated on Mon Jan 16 13:23:47 2006 for IPPL by  doxygen 1.4.6