From 249117c89e4d28fa714f03f9026df84f49e91f0c Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Tue, 24 Jun 2008 18:59:06 +0000 Subject: [PATCH] serial and parallel code merged --- test/H5PartTest.cc | 513 ++++++++++++++++++++------------------------- 1 file changed, 233 insertions(+), 280 deletions(-) diff --git a/test/H5PartTest.cc b/test/H5PartTest.cc index bd9b5db..c217979 100644 --- a/test/H5PartTest.cc +++ b/test/H5PartTest.cc @@ -10,289 +10,242 @@ */ + +int main(int argc,char *argv[]){ + int sz=5; + double *x,*y,*z; + h5part_int64_t *id; + H5PartFile *file; + int i,t,nt,nds, np; + int nprocs = 1; + int myproc = 0; + #ifdef PARALLEL_IO + MPI_Comm comm=MPI_COMM_WORLD; -int main(int argc,char *argv[]){ - int sz=5; - double *x,*y,*z; - h5part_int64_t *id; - H5PartFile *file; - int i,t,nt,nds; - int nprocs,myproc; - MPI_Comm comm=MPI_COMM_WORLD; - - MPI_Init(&argc,&argv); - MPI_Comm_size(comm,&nprocs); - MPI_Comm_rank(comm,&myproc); - - x=(double*)malloc(sz*nprocs*sizeof(double)); - y=(double*)malloc(sz*nprocs*sizeof(double)); - z=(double*)malloc(sz*nprocs*sizeof(double)); - id=(h5part_int64_t*)malloc(sz*nprocs*sizeof(h5part_int64_t)); - /* parallel file creation */ - file=H5PartOpenFileParallel("parttest.h5",H5PART_WRITE,comm); - if(!file) { - perror("File open failed: exiting!"); - exit(0); - } - - for(t=0;t<5;t++){ - MPI_Barrier(comm); - for(i=0;ifile); - H5PartSetStep(file,t); /* must set the current timestep in file */ - H5PartSetNumParticles(file,sz); /* then set number of particles to store */ - /* now write different tuples of data into this timestep of the file */ - H5PartWriteDataFloat64(file,"x",x); - H5PartWriteDataFloat64(file,"y",y); - H5PartWriteDataFloat64(file,"z",z); - - H5PartWriteDataFloat64(file,"px",x); - H5PartWriteDataFloat64(file,"py",y); - H5PartWriteDataFloat64(file,"pz",z); - - H5PartWriteDataInt64(file,"id",id); - } - - unsigned int idStart = 0+sz*myproc; - unsigned int idEnd = (sz-1)+sz*myproc; - - printf("AllDone p[%u]\n",myproc); - H5PartCloseFile(file); - fprintf(stderr,"Closed files p[%u]\n",myproc); - MPI_Barrier(comm); - - fprintf(stderr,"p[%u:%u] : OK, close file and reopen for reading idStart %u idEnd %u \n",myproc,nprocs,idStart,idEnd); - - file=H5PartOpenFileParallel("parttest.h5",H5PART_READ,comm); - H5PartSetStep(file,0); - // unsigned int np = 0; - unsigned int np = (int)H5PartGetNumParticles(file); - nt=H5PartGetNumSteps(file); /* get number of steps in file */ - nds=H5PartGetNumDatasets(file); /* get number of datasets in timestep 0 */ - - MPI_Barrier(comm); - - H5PartSetView(file,idStart,idEnd); - - np = (int)H5PartGetNumParticles(file); - printf("After SetView(%d,%d): steps= %u datasets= %u particles= %u\n", - (int)idStart,(int)idEnd, - nt,nds,np); - - if(x) - free(x); - if(y) - free(y); - if(z) - free(z); - if(id) - free(id); - - H5PartCloseFile(file); - MPI_Barrier(comm); - fprintf(stderr,"proc[%u]: done\n",myproc); - return MPI_Finalize(); -} - -#else -int main(int argc,char *argv[]){ - int sz=10; - double *x,*y,*z; - h5part_int64_t *id; - H5PartFile *file; - int i,t,nt,nds,np; - h5part_int64_t idStart = 0; - h5part_int64_t idEnd = 0; - - - x=(double*)malloc(sz*sizeof(double)); - y=(double*)malloc(sz*sizeof(double)); - z=(double*)malloc(sz*sizeof(double)); - id=(h5part_int64_t*)malloc(sz*sizeof(h5part_int64_t)); - /* parallel file creation */ - file=H5PartOpenFile("parttest.h5",H5PART_WRITE); - if(!file) { - perror("File open failed: exiting!"); - exit(0); - } - - H5PartWriteFileAttribString(file,"File Description", "This file is created by H5PartTest.cc. Simple H5Part file for testing purpose..."); - char* FileAttrib = "Created by H5PartTest.cc"; - H5PartWriteFileAttrib(file, "Origin", H5T_NATIVE_CHAR, FileAttrib ,strlen(FileAttrib)); - - for(t=0;t<5;t++){ - fprintf(stdout,"Writing timestep %u\n",t); - for(i=0;i>1); - printf("Set new view = %d:%d\n",(int)idStart,(int)(idEnd>>1)); - H5PartGetView(file,&idStart,&idEnd); - np=H5PartGetNumParticles(file); - printf("steps= %u datasets= %u particles= %d with view %d:%d\n", - nt,nds,(int)np,(int)idStart,(int)idEnd); - H5PartSetStep(file,nt-1); // set to last step - printf("Setting to last step = %u\n",nt-1); - for(i=0;i<10;i++){ x[i]=y[i]=z[i]=0.0; id[i]=0; } /* clear the arrays */ - H5PartReadDataFloat64(file,"x",x); - H5PartReadDataFloat64(file,"y",y); - H5PartReadDataFloat64(file,"z",z); - H5PartReadDataInt64(file,"id",id); - - for(i=0;i>1,(int)idEnd); - H5PartSetView(file,(idEnd>>1),idEnd); - np=H5PartGetNumParticles(file); - printf("Now particles in selection are %d\n",np); - printf("doubleCheck=%lld\n", (long long)H5PartGetView(file,0,0)); - - for(i=0;i<10;i++){ x[i]=y[i]=z[i]=0.0; id[i]=0; } /* clear the arrays */ - - H5PartReadDataFloat64(file,"x",x); - H5PartReadDataFloat64(file,"y",y); - H5PartReadDataFloat64(file,"z",z); - H5PartReadDataInt64(file,"id",id); - for(i=0;ifile); + H5PartSetStep(file,t); /* must set the current timestep in file */ + H5PartSetNumParticles(file,sz); /* then set number of particles to store */ + /* now write different tuples of data into this timestep of the file */ + H5PartWriteDataFloat64(file,"x",x); + H5PartWriteDataFloat64(file,"y",y); + H5PartWriteDataFloat64(file,"z",z); + + H5PartWriteDataFloat64(file,"px",x); + H5PartWriteDataFloat64(file,"py",y); + H5PartWriteDataFloat64(file,"pz",z); + + H5PartWriteDataInt64(file,"id",id); + if ( myproc == 0 ) { + H5PartWriteStepAttribString ( + file, + "Step Description", + "STEP STEP STEP" + ); + } + + } + + h5part_int64_t idStart = 0+sz*myproc; + h5part_int64_t idEnd = (sz-1)+sz*myproc; + + printf("AllDone p[%u]\n",myproc); + H5PartCloseFile(file); + fprintf(stderr,"Closed files p[%u]\n",myproc); +#ifdef PARALLEL_IO + MPI_Barrier(comm); +#endif + fprintf ( + stderr, + "p[%u:%u] : OK, close file and reopen for reading idStart %lld idEnd %lld \n", + myproc, nprocs, (long long)idStart, + (long long)idEnd ); + +#ifdef PARALLEL_IO + file = H5PartOpenFileParallel ( "parttest.h5", H5PART_READ, comm ); +#else + file = H5PartOpenFile ( "parttest.h5", H5PART_READ ); +#endif + H5PartSetStep(file,0); + nt = H5PartGetNumSteps(file); /* get number of steps in file */ + nds = H5PartGetNumDatasets(file); /* get number of datasets in timestep 0 */ + np = H5PartGetNumParticles(file); + + H5PartSetView(file,idStart,idEnd); + + np = (int)H5PartGetNumParticles(file); + printf("After SetView(%d,%d): steps= %u datasets= %u particles= %u\n", + (int)idStart,(int)idEnd, + nt,nds,np); + +#ifdef PARALLEL_IO + MPI_Barrier(comm); +#endif + // clear the particles + for(i=0;i>1); + printf("Set new view = %d:%d\n",(int)idStart,(int)(idEnd>>1)); + H5PartGetView(file,&idStart,&idEnd); + np=H5PartGetNumParticles(file); + printf("steps= %u datasets= %u particles= %d with view %d:%d\n", + nt,nds,(int)np,(int)idStart,(int)idEnd); + H5PartSetStep(file,nt-1); // set to last step + printf("Setting to last step = %u\n",nt-1); + for(i=0;i<10;i++){ x[i]=y[i]=z[i]=0.0; id[i]=0; } /* clear the arrays */ + H5PartReadDataFloat64(file,"x",x); + H5PartReadDataFloat64(file,"y",y); + H5PartReadDataFloat64(file,"z",z); + H5PartReadDataInt64(file,"id",id); + + for(i=0;i>1,(int)idEnd); + H5PartSetView(file,(idEnd>>1),idEnd); + np=H5PartGetNumParticles(file); + printf("Now particles in selection are %d\n",np); + printf("doubleCheck=%lld\n", (long long)H5PartGetView(file,0,0)); + + for(i=0;i<10;i++){ x[i]=y[i]=z[i]=0.0; id[i]=0; } /* clear the arrays */ + + H5PartReadDataFloat64(file,"x",x); + H5PartReadDataFloat64(file,"y",y); + H5PartReadDataFloat64(file,"z",z); + H5PartReadDataInt64(file,"id",id); + for(i=0;i