examples Bench.c, H5test.c and H5testF.f90 removed

This commit is contained in:
2013-09-26 16:47:51 +02:00
parent 11e399b6c7
commit 006e1cda4a
3 changed files with 0 additions and 1450 deletions
-263
View File
@@ -1,263 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpi.h>
/* #include <mpio.h> */
#include <unistd.h>
#include <sys/types.h>
#ifndef PARALLEL_IO
#define PARALLEL_IO
#endif
#ifndef DISABLE_H5PART
#include "H5hut.h"
#endif
#define FILENAME "testio"
/* normally 64 steps for real benchmark */
/* #define NSTEPS 5 */
/* normally 51e6 for real benchmark */
#define NPARTICLES 51e4
#define NTRIALS 3
/*
bench <nParticles> <nSteps>
*/
int main(int argc,char *argv[]){
if (argc < 3) {
printf("Usage: bench <nParticles> <nSteps> \n");
exit(-1);
}
else {
printf("nparticles: %d, nsteps: %d \n", atoi(argv[1]), atoi(argv[2]));
}
MPI_Info info;
int nprocs,rank;
int trial;
int i,j,n; /* iteration variables */
double starttime,curtime, endtime;
int nparticles = atoi(argv[1]);
int nsteps = atoi(argv[2]);
double *x,*y,*z,*px,*py,*pz;
typedef double *ddouble;
ddouble data[6];
MPI_Datatype chunktype;
int offset;
int localnp;
char filename[128]; /*= FILENAME; */
#ifndef DISABLE_H5PART
h5_file_t f;
#endif
char newfilename[128];
FILE *fd;
MPI_File file;
MPI_Offset foffset;
MPI_Comm dcomm = MPI_COMM_WORLD;
MPI_Init(&argc,&argv);
MPI_Comm_rank(dcomm,&rank);
MPI_Comm_size(dcomm,&nprocs);
localnp=nparticles/(int64_t)nprocs;
for(offset=0,i=0;i<rank;i++){
offset+=localnp;
}
data[0]=x=(double*)malloc(sizeof(double)*(size_t)localnp);
data[1]=y=(double*)malloc(sizeof(double)*(size_t)localnp);
data[2]=z=(double*)malloc(sizeof(double)*(size_t)localnp);
data[3]=px=(double*)malloc(sizeof(double)*(size_t)localnp);
data[4]=py=(double*)malloc(sizeof(double)*(size_t)localnp);
data[5]=pz=(double*)malloc(sizeof(double)*(size_t)localnp);
/* printf("about to call create subarray with nparticles=%u localnp=%u offset=%u\n",
nparticles,localnp,offset); */
MPI_Type_create_subarray(1, /* rank */
&nparticles, /* size of the global array */
&localnp, /* size of my local chunk */
&offset, /* offset of this chunk in global */
MPI_ORDER_FORTRAN, /* fortran storage order */
MPI_DOUBLE,
&chunktype);
MPI_Type_commit(&chunktype);
MPI_Info_create(&info);
MPI_Info_set(info, "IBM_largeblock_io", "true" );
if(rank==0) printf("Nprocs=%u Particles=%u*6attribs*sizeof(double) Particles/proc=%u Nsteps=%u Ntrials=%u\n",
nprocs,nparticles,localnp,nsteps,NTRIALS);
for(trial=0;trial<NTRIALS;trial++){
if(rank==0) printf("---------------------- Trial %u of %u ---------------------\n",trial+1,NTRIALS);
MPI_Barrier(MPI_COMM_WORLD); /* to prevent unlink from interfering with file open */
sprintf(filename,"%s.%u.mpio.dat",FILENAME,nprocs);
if(rank==0) unlink(filename);
MPI_Barrier(MPI_COMM_WORLD); /* to prevent unlink from interfering with file open */
MPI_File_open(MPI_COMM_WORLD,filename,
MPI_MODE_CREATE | MPI_MODE_RDWR,
info,&file);
MPI_File_set_view(file,0,MPI_DOUBLE,chunktype,"native",info);
/* now a barrier to get the start timers roughly synced*/
MPI_Barrier(MPI_COMM_WORLD);
curtime = starttime = MPI_Wtime();
endtime = starttime+5.0*60.0; /* end in 5 minutes */
MPI_Bcast(&endtime,1,MPI_DOUBLE,0,MPI_COMM_WORLD);
/* must touch the entire array after each write */
/* ensures cache-invalidation */
foffset=0;
i=0;
curtime=starttime;
for(i=0;i<nsteps;i++){
int n;
MPI_Status status;
for(j=0;j<6;j++){
/* touch data */
for(n=0;n<localnp;n++)
(data[j])[n]=(double)rank;
/* write to that file */
/* MPI_File_set_view(file,foffset,MPI_DOUBLE,chunktype,"native",info);*/
#ifdef COLLECTIVE_IO
MPI_File_write_at_all(file,
foffset,
data[j],
localnp,
MPI_DOUBLE,&status);
#else
MPI_File_write_at(file,
foffset,
data[j],
localnp,
MPI_DOUBLE,&status);
#endif
foffset+=nparticles/nprocs;
}
curtime=MPI_Wtime(); /* ensure no race condition by broadcasting time */
MPI_Bcast(&curtime,1,MPI_DOUBLE,0,MPI_COMM_WORLD);
}
MPI_File_close(&file);
MPI_Barrier(MPI_COMM_WORLD);
endtime=MPI_Wtime();
/* foffset*=nprocs; if we want total megabytes written */
if(rank==0){
puts("*");
unlink(filename);
puts("======================================================");
printf("Raw MPI-IO Total Duration %lf seconds, iterations=%u %lf Megabytes written per processor Nprocs= %u \n",
(endtime-starttime),i,((double)foffset)/(1024.0*1024.0),nprocs);
printf("Raw MPI-IO Effective Data Rate = %lf Megabytes/sec global and %lf Megabytes/sec per task Nprocs= %u \n",
(double)(nprocs*localnp*sizeof(double))*((double)nsteps)*6.0/((endtime-starttime)*1024.0*1024.0),
(double)(localnp*sizeof(double))*((double)nsteps)*6.0/((endtime-starttime)*1024.0*1024.0),nprocs);
puts("======================================================");
}
MPI_Barrier(MPI_COMM_WORLD); /* to prevent unlink from interfering with file open */
/* OK, now we do this using POSIX IO */
sprintf(newfilename,"testio%u.%u.dat",rank,nprocs);
unlink(newfilename);
MPI_Barrier(MPI_COMM_WORLD); /* to prevent unlink from interfering with file open */
fd = fopen(newfilename,"w");
/* start the timer */
starttime=endtime=MPI_Wtime();
for(i=0;i<nsteps;i++){
for(j=0;j<6;j++){
/* touch data */
for(n=0;n<localnp;n++)
(data[j])[n]=(double)rank;
fwrite(data[j],sizeof(double),localnp,fd);
}
curtime=MPI_Wtime(); /* ensure no race condition by broadcasting time */
MPI_Bcast(&curtime,1,MPI_DOUBLE,0,MPI_COMM_WORLD);
}
fclose(fd);
MPI_Barrier(MPI_COMM_WORLD);
endtime=MPI_Wtime();
if(rank==0) puts("*");
MPI_Barrier(MPI_COMM_WORLD); /* to prevent unlink from interfering with file open */
unlink(newfilename);
MPI_Barrier(MPI_COMM_WORLD);
if(rank==0){
puts("======================================================");
printf("Raw 1-file-per-proc Total Duration %lf seconds, iterations=%u %lf Megabytes written Nprocs= %u \n",
(endtime-starttime),nsteps,((double)foffset)/(1024.0*1024.0),nprocs);
printf("Raw 1-file-per-proc Effective Data Rate = %lf Megabytes/sec global and %lf Megabytes/sec per task Nprocs= %u \n",
(double)(nprocs*localnp*sizeof(double))*((double)nsteps)*6.0/((endtime-starttime)*1024.0*1024.0),
(double)(localnp*sizeof(double))*((double)nsteps)*6.0/((endtime-starttime)*1024.0*1024.0),nprocs);
puts("======================================================");
}
#ifndef DISABLE_H5PART
MPI_Barrier(MPI_COMM_WORLD); /* to prevent unlink from interfering with file open */
/* OK, now we do this using H5Part */
sprintf(filename,"%s.%u.h5.dat",FILENAME,nprocs);
if(rank==0) unlink(filename);
MPI_Barrier(MPI_COMM_WORLD); /* to prevent unlink from interfering with file open */
f = H5OpenFile(filename,H5_O_WRONLY,MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD); /* to prevent unlink from interfering with file open */
/* start the timer */
starttime=endtime=MPI_Wtime();
H5PartSetNumParticles(f,localnp);
for(i=0;i<nsteps;i++){
for(j=0;j<6;j++){
/* touch data */
for(n=0;n<localnp;n++)
(data[j])[n]=(double)rank;
}
H5SetStep(f,i);
H5PartWriteDataFloat64(f,"x",x);
H5PartWriteDataFloat64(f,"y",y);
H5PartWriteDataFloat64(f,"z",z);
H5PartWriteDataFloat64(f,"px",px);
H5PartWriteDataFloat64(f,"py",py);
H5PartWriteDataFloat64(f,"pz",pz);
curtime=MPI_Wtime(); /* ensure no race condition by broadcasting time */
MPI_Bcast(&curtime,1,MPI_DOUBLE,0,MPI_COMM_WORLD);
}
H5CloseFile(f);
MPI_Barrier(MPI_COMM_WORLD);
endtime=MPI_Wtime();
if(rank==0){
puts("*");
unlink(filename);
puts("======================================================");
printf("H5Part Total Duration %lf seconds, iterations=%u %lf Megabytes written Nprocs= %u \n",
(endtime-starttime),nsteps,((double)foffset)/(1024.0*1024.0),nprocs);
printf("H5Part Effective Data Rate = %lf Megabytes/sec global and %lf Megabytes/sec per task Nprocs= %u \n",
(double)(nprocs*localnp*sizeof(double))*((double)nsteps)*6.0/((endtime-starttime)*1024.0*1024.0),
(double)(localnp*sizeof(double))*((double)nsteps)*6.0/((endtime-starttime)*1024.0*1024.0),nprocs);
puts("======================================================");
}
MPI_Barrier(MPI_COMM_WORLD);
#endif
} /* trials */
MPI_Finalize();
return 0;
}
-263
View File
@@ -1,263 +0,0 @@
#include <stdlib.h>
#include "H5hut.h"
/*
A simple regression test that shows how you use this API
to write and read multi-timestep files of particle data.
*/
#ifdef PARALLEL_IO
int main(int argc,char *argv[]){
int sz=5;
double *x,*y,*z;
h5_int64_t *id;
h5_file_t file;
int i,t,nt,nds;
int nprocs = 1;
int myproc = 0;
MPI_Comm comm = MPI_COMM_WORLD;
#if PARALLEL_IO
MPI_Init (&argc,&argv);
MPI_Comm_size (comm,&nprocs);
MPI_Comm_rank (comm,&myproc);
#endif
x = (double*)malloc (sz*nprocs*sizeof(double));
y = (double*)malloc (sz*nprocs*sizeof(double));
z = (double*)malloc (sz*nprocs*sizeof(double));
id=(h5_int64_t*)malloc (sz*nprocs*sizeof(h5_int64_t));
file=H5OpenFile ("parttest.h5",H5_O_WRONLY,comm);
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++){
MPI_Barrier(comm);
for(i=0;i<sz;i++) {
x[i]=(double)(i+t)+10.0*(double)myproc;
y[i]=0.1 + (double)(i+t);
z[i]=0.2 + (double)(i+t*10);
id[i]=i+sz*myproc;
}
printf("Proc[%u] Writing timestep %u \n",myproc,t);
H5SetStep(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);
H5PartWriteStepAttribString (
file,
"Step Description",
"STEP STEP STEP");
char* StepAttrib = "STEP";
H5PartWriteStepAttrib (
file,
"Step",
H5T_NATIVE_CHAR,
StepAttrib ,strlen(StepAttrib));
}
printf("Done writing p[%u]\n",myproc);
H5CloseFile(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);
unsigned int idStart = 0+sz*myproc;
unsigned int idEnd = (sz-1)+sz*myproc;
file=H5OpenFile("parttest.h5",H5_O_RDONLY,comm);
H5SetStep(file,0);
// unsigned int np = 0;
unsigned int np = (int)H5PartGetNumParticles(file);
nt=H5GetNumSteps(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);
free(x);
free(y);
free(z);
free(id);
H5CloseFile(file);
MPI_Barrier(comm);
fprintf(stderr,"proc[%u]: done\n",myproc);
return MPI_Finalize();
}
#else
/*+++++++++++++ Reopen File for Reading +++H5PartSetStep(h5partFile,0)++++++++*/
file=H5PartOpenFile("parttest.h5",H5_O_RDONLY);
/********************************************/
H5PartSetStep(file,0);
nt=H5GetNumSteps(file); /* get number of steps in file */
nds=H5PartGetNumDatasets(file); /* get number of datasets in timestep 0 */
np=H5PartGetNumParticles(file);
fprintf(stdout,"OK, close file and reopen for reading\n");
fprintf(stdout,"steps= %u\tdatasets=%u\tparticles= %u\n",
nt,nds,np);
// clear the particles
for(i=0;i<np;i++){
x[i]=y[i]=z[i]=0.0;
id[i]=0;
}
H5PartReadDataFloat64(file,"x",x);
H5PartReadDataFloat64(file,"y",y);
H5PartReadDataFloat64(file,"z",z);
H5PartReadDataInt64(file,"id",id);
for(i=0;i<np;i++){
fprintf(stdout,
"\tp[%3u] x=%lf y=%lf z=%lf id=%lld\n",
i,x[i],y[i],z[i],(long long)(id[i]));
}
/************************ std::cout << "nParticles: " << nParticles << std::endl;
********************/
printf("Set to last step and reload data\n");
H5PartSetStep(file,nt-1);
H5PartReadDataFloat64(file,"x",x);
H5PartReadDataFloat64(file,"y",y);
H5PartReadDataFloat64(file,"z",z);
H5PartReadDataInt64(file,"id",id);
for(i=0;i<np;i++){
fprintf(stdout,"\tp[%3u] x=%lf y=%lf z=%lf id=%lld\n",
i,x[i],y[i],z[i],(long long) (id[i]));
}
/********************************************/
idEnd=np;
printf("Old View is %d:%d\n",(int)idStart,(int)idEnd);
H5PartSetView(file,idStart,idEnd>>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<np;i++){
fprintf(stdout,
"\tp[%3u] x=%lf y=%lf z=%lf id=%lld\n",
i,x[i],y[i],z[i],(long long)id[i]);
}
/********************************************/
printf("Now set the view to the latter half of the data in step #%u\n",nt-1);
H5PartResetView(file);
H5PartGetView(file,&idStart,&idEnd);
printf("Reset view = %d:%d\nSetting to %u:%u\n",
(int)idStart,(int)idEnd,
(int)idEnd>>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<np;i++){
fprintf(stdout,
"\tp[%3u] x=%lf y=%lf z=%lf id=%lld\n",
i,x[i],y[i],z[i],(long long)id[i]);
}
// read dataset names
h5_int64_t status = H5_SUCCESS;
const h5_int64_t lenName = 64;
char datasetName[lenName];
h5_int64_t datasetType;
h5_int64_t datasetNElems;
H5PartSetStep(file,0);
for (h5_int64_t i=0; i < nds; i++) {
status = H5PartGetDatasetInfo(file, i, datasetName, lenName,
&datasetType, &datasetNElems);
if (status != H5_SUCCESS) {
perror("Could not retrieve dataset names!");
}
else {
printf("datasetName: %s, type: %lld, nElements: %lld ",
datasetName, datasetType, datasetNElems);
if (datasetType == H5_INT64_T) {
printf("H5PPART_INT64 \n");
}
else {
printf("H5PPART_FLOAT64 \n");
}
}
}
if(x)
free(x);
if(y)
free(y);
if(z)
free(z);
if(id)
free(id);
H5PartCloseFile(file);
fprintf(stderr,"done\n");
}
#endif
-924
View File
@@ -1,924 +0,0 @@
PROGRAM H5PartExampleF
IMPLICIT NONE
#ifdef PARALLEL_IO
INCLUDE 'mpif.h'
#endif
INCLUDE 'H5hutF.h'
INTEGER*8 :: h5_err = 0
INTEGER :: mpi_err
INTEGER :: num_args = 0
INTEGER :: i
CHARACTER(LEN=32) :: arg_str
INTEGER :: opt_read = 0
INTEGER :: opt_write = 0
INTEGER*8 :: opt_debug = 2
INTEGER :: comm = 0
INTEGER :: myproc = 0
INTEGER :: num_procs = 0
CHARACTER(LEN=128) :: fname = "testfile.h5"
INTEGER*8 :: file
REAL*8 :: r8_attrib (2)
REAL*4 :: r4_attrib (2)
INTEGER*8 :: i8_attrib (2)
INTEGER*4 :: i4_attrib (2)
CHARACTER (LEN=H5_MAX_NAME_LEN) :: string_attrib
LOGICAL skip
DATA r8_attrib / 42.0, 43.0 /
DATA r4_attrib / 42.0, 43.0 /
DATA i8_attrib / 42, 43 /
DATA i4_attrib / 42, 43 /
DATA string_attrib / "The answer is 42." /
num_args = IARGC ()
IF (num_args == 0) THEN
PRINT *, "Usage: H5PartExampleF -w | -r [-g]"
CALL EXIT (1)
END IF
DO i = 1, num_args
PRINT *, "Loop..."
if (skip .EQV. .TRUE.) THEN
CYCLE
END IF
CALL GETARG (i, arg_str)
IF (arg_str == "-r") THEN
opt_read = 1
ELSE IF (arg_str == "-w") THEN
opt_write = 1
ELSE IF (arg_str == "-d") THEN
CALL GETARG (i+1, arg_str)
arg_str = TRIM (arg_str)
READ (arg_str, *, ERR=999) opt_debug
skip = .TRUE.
CYCLE
999 PRINT *, "Debug level must be an integer: ", arg_str
CALL EXIT (1)
ELSE
PRINT *, "Illegal option ", arg_str, "\n"
PRINT *, "Usage: H5BlockExampleF -w | -r [-d LEVEL]"
CALL EXIT (1)
END IF
END DO
#ifdef PARALLEL_IO
CALL MPI_Init (mpi_err)
comm = MPI_COMM_WORLD
CALL MPI_Comm_rank (comm, myproc, mpi_err)
CALL MPI_Comm_size (comm, num_procs, mpi_err)
h5_err = h5_set_verbosity_level (opt_debug)
IF (opt_write == 1) THEN
PRINT "('[proc ', I3, ']: Open file for writing ...')", myproc
file = h5_openw_par (fname, comm)
IF (file == 0) THEN
PRINT "('[proc ', I3, ']: Error opening file ...')", myproc
h5_err = -2
GOTO 911
ENDIF
h5_err = write_file (file, myproc, num_procs)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Failed to write file ', A, '!')", myproc, fname
GOTO 911
END IF
ELSE IF (opt_read == 1) THEN
PRINT "('[proc ', I3, ']: Open file for reading ...')", myproc
file = h5_openr_par (fname, comm)
IF (file == 0) THEN
PRINT "('[proc ', I3, ']: Error opening file ...')", myproc
GOTO 911
ENDIF
h5_err = read_file (file, myproc, num_procs)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Failed to read file ', A, '!')", myproc, fname
GOTO 911
END IF
ENDIF
PRINT "('[proc ', I3, ']: Done.')", myproc
911 CONTINUE
h5_err = h5_close (file)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error closing file ...')", myproc
ENDIF
PRINT "('[proc ', I3, ']: File closed.')", myproc
h5_err = h5_finalize ()
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error closing H5hut library ...')", myproc
ENDIF
PRINT "('[proc ', I3, ']: H5hut finalized.')", myproc
CALL MPI_Finalize (mpi_error)
PRINT "('[proc ', I3, ']: MPI finalized.')", myproc
#else
!! SERIAL CODE
h5_err = h5_set_verbosity_level (opt_debug)
IF (opt_write == 1) THEN
PRINT "('[proc ', I3, ']: Open file for writing ...')", myproc
file = h5_openw (fname)
IF (file == 0) THEN
PRINT "('[proc ', I3, ']: Error opening file ...')", myproc
h5_err = -2
GOTO 911
ENDIF
h5_err = write_file (file, myproc, num_procs)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Failed to write file ', A, '!')", myproc, fname
GOTO 911
END IF
ELSE IF (opt_read == 1) THEN
file = h5_openr (fname)
IF (file == 0) THEN
PRINT "('[proc ', I3, ']: Error opening file ...')", myproc
GOTO 911
ENDIF
h5_err = read_file (file, myproc, num_procs)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Failed to read file ', A, '!')", myproc, fname
GOTO 911
END IF
ENDIF
PRINT "('[proc ', I3, ']: Done.')", myproc
911 CONTINUE
h5_err = h5_close (file)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error closing file ...')", myproc
ENDIF
#endif
CALL EXIT (h5_err)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
CONTAINS
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
INTEGER*8 FUNCTION write_file (file, myproc, num_procs)
IMPLICIT NONE
INTEGER*8, INTENT(IN) :: file
INTEGER, INTENT(IN) :: myproc
INTEGER, INTENT(IN) :: num_procs
INCLUDE 'H5hutF.h'
INTEGER :: mpi_err
INTEGER*8 :: step = 1
INTEGER*8 :: num_steps = 2
h5_err = write_file_attribs (file, myproc)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing file attributes ...')", myproc
write_file = h5_err
RETURN
ENDIF
DO step = 1, num_steps
h5_err = h5_setstep (file, step)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error setting step to ', I2)", myproc, step
write_file = h5_err
RETURN
ENDIF
h5_err = write_step_attribs (file, myproc, num_procs)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing step attributes ...')", myproc
write_file = h5_err
RETURN
ENDIF
h5_err = write_data (file, myproc, num_procs)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing step data ...')", myproc
write_file = h5_err
RETURN
ENDIF
ENDDO
write_file = 0
END FUNCTION write_file
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
INTEGER*8 FUNCTION write_file_attribs (file, myproc)
IMPLICIT NONE
INTEGER*8, INTENT(IN) :: file
INTEGER, INTENT(IN) :: myproc
INCLUDE 'H5hutF.h'
PRINT "('[proc ', I3, ']: Writing file attribute of type H5_FLOAT64_T ...')", myproc
h5_err = h5_writefileattrib_r8 (file, "r8_attrib", r8_attrib, 2_8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing file attribute of type H5_FLOAT64_T')", myproc
write_file_attribs = h5_err
RETURN
ENDIF
PRINT "('[proc ', I3, ']: Writing file attribute of type H5_FLOAT32_T ...')", myproc
h5_err = h5_writefileattrib_r4 (file, "r4_attrib", r4_attrib, 2_8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing file attribute of type H5_FLOAT32_T')", myproc
write_file_attribs = h5_err
RETURN
ENDIF
PRINT "('[proc ', I3, ']: Writing file attribute of type H5_INT64_T ...')", myproc
h5_err = h5_writefileattrib_i8 (file, "i8_attrib", i8_attrib, 2_8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing file attribute of type H5_INT64_T')", myproc
write_file_attribs = h5_err
RETURN
ENDIF
PRINT "('[proc ', I3, ']: Writing file attribute of type H5_INT32_T ...')", myproc
h5_err = h5_writefileattrib_i4 (file, "i4_attrib", i4_attrib, 2_8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing file attribute of type H5_INT32_T')", myproc
write_file_attribs = h5_err
RETURN
ENDIF
PRINT "('[proc ', I3, ']: Writing file attribute of type H5_STRING_T ...')", myproc
h5_err = h5_writefileattrib_string (file, "string_attrib", string_attrib)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing file attribute of type H5_STRING_T')", myproc
write_file_attribs = h5_err
RETURN
ENDIF
write_file_attribs = 0
END FUNCTION write_file_attribs
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
INTEGER*8 FUNCTION write_step_attribs (file, myproc, num_procs)
IMPLICIT NONE
INTEGER*8, INTENT(IN) :: file
INTEGER, INTENT(IN) :: myproc
INTEGER, INTENT(IN) :: num_procs
INCLUDE 'H5hutF.h'
PRINT "('[proc ', I3, ']: Writing step attribute of type H5_FLOAT64_T ...')", myproc
h5_err = h5_writestepattrib_r8 (file, "r8_attrib", r8_attrib, 2_8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing step attribute of type H5_FLOAT64_T')", myproc
write_step_attribs = h5_err
RETURN
ENDIF
PRINT "('[proc ', I3, ']: Writing step attribute of type H5_FLOAT32_T ...')", myproc
h5_err = h5_writestepattrib_r4 (file, "r4_attrib", r4_attrib, 2_8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing step attribute of type H5_FLOAT32_T')", myproc
write_step_attribs = h5_err
RETURN
ENDIF
PRINT "('[proc ', I3, ']: Writing step attribute of type H5_INT64_T ...')", myproc
h5_err = h5_writestepattrib_i8 (file, "i8_attrib", i8_attrib, 2_8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing step attribute of type H5_INT64_T')", myproc
write_step_attribs = h5_err
RETURN
ENDIF
PRINT "('[proc ', I3, ']: Writing step attribute of type H5_INT32_T ...')", myproc
h5_err = h5_writestepattrib_i4 (file, "i4_attrib", i4_attrib, 2_8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing step attribute of type H5_INT32_T')", myproc
write_step_attribs = h5_err
RETURN
ENDIF
PRINT "('[proc ', I3, ']: Writing step attribute of type H5_STRING_T ...')", myproc
h5_err = h5_writestepattrib_string (file, "string_attrib", string_attrib)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing step attribute of type H5_STRING_T')", myproc
write_step_attribs = h5_err
RETURN
ENDIF
write_step_attribs = 0
END FUNCTION write_step_attribs
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
INTEGER*8 FUNCTION write_data (file, myproc, num_procs)
IMPLICIT NONE
INTEGER*8, INTENT(IN) :: file
INTEGER, INTENT(IN) :: myproc
INTEGER, INTENT(IN) :: num_procs
INCLUDE 'H5hutF.h'
INTEGER*8 :: h5_err = 0
REAL*8, ALLOCATABLE :: r8_data (:)
REAL*4, ALLOCATABLE :: r4_data (:)
INTEGER*8, ALLOCATABLE :: i8_data (:)
INTEGER*4, ALLOCATABLE :: i4_data (:)
INTEGER*8 :: num_points = 1024
INTEGER*8 :: offset = 0
INTEGER*8 :: step = 1
ALLOCATE (r8_data (num_points))
ALLOCATE (r4_data (num_points))
ALLOCATE (i8_data (num_points))
ALLOCATE (i4_data (num_points))
step = h5_getstep (file)
offset = num_points * myproc
DO i = 1, num_points
r8_data (i) = REAL (i + offset + step)
r4_data (i) = REAL (i + offset + step)
i8_data (i) = i + offset + step
i4_data (i) = i + offset + step
ENDDO
h5_err = h5pt_setnpoints (file, num_points)
PRINT "('[proc ', I3, ']: Writing file data of type H5_FLOAT64_T ...')", myproc
h5_err = h5pt_writedata_r8 (file,"r8_data", r8_data)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing r8 data')", myproc
write_data = h5_err
RETURN
ENDIF
PRINT "('[proc ', I3, ']: Writing file data of type H5_FLOAT32_T ...')", myproc
h5_err = h5pt_writedata_r4 (file,"r4_data", r4_data)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing r4 data')", myproc
write_data = h5_err
RETURN
ENDIF
PRINT "('[proc ', I3, ']: Writing file data of type H5_INT64_T ...')", myproc
h5_err = h5pt_writedata_i8 (file,"i8_data", i8_data)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing i8 data')", myproc
write_data = h5_err
RETURN
ENDIF
PRINT "('[proc ', I3, ']: Writing file data of type H5_INT32_T ...')", myproc
h5_err = h5pt_writedata_i4 (file,"i4_data", i4_data)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error writing i4 data')", myproc
write_data = h5_err
RETURN
ENDIF
write_data = 0
END FUNCTION write_data
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
INTEGER*8 FUNCTION read_file (file, myproc, num_procs)
IMPLICIT NONE
INTEGER*8, INTENT(IN) :: file
INTEGER, INTENT(IN) :: myproc
INTEGER, INTENT(IN) :: num_procs
INCLUDE 'H5hutF.h'
INTEGER :: mpi_err
INTEGER*8 :: step = 1
INTEGER*8 :: num_steps = 0
h5_err = read_file_attribs (file, myproc, num_procs)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading file attributes ...')", myproc
read_file = h5_err
RETURN
ENDIF
num_steps = h5_getnsteps (file)
PRINT "('[proc ', I3, ']: Number of steps = ', I3)", myproc, num_steps
DO step = 1, num_steps
PRINT "('[proc ', I3, ']: Set step = ', I3)", myproc, step
h5_err = h5_setstep (file, step)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error setting step to ', I2)", myproc, step
read_file = h5_err
RETURN
ENDIF
h5_err = read_step_attribs (file, myproc, num_procs)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading step data ...')", myproc
read_file = h5_err
RETURN
ENDIF
h5_err = read_data (file, myproc, num_procs)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading step attributes ...')", myproc
read_file = h5_err
RETURN
ENDIF
ENDDO
read_file = 0
911 CONTINUE
END FUNCTION read_file
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
INTEGER*8 FUNCTION cmp_i4 (x, y, size)
IMPLICIT NONE
INTEGER*4, DIMENSION (1:size), INTENT (IN) :: x, y
INTEGER*8, INTENT (IN) :: size
INTEGER*8 i
DO i = 1, size
IF (x (i) /= y (i)) THEN
PRINT "('[proc ', I3, ']: Value error ', I6, ' /= ', I6)", &
myproc, x (i), y (i)
cmp_i4 = -2
RETURN
END IF
END DO
cmp_i4 = 0
END FUNCTION cmp_i4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
INTEGER*8 FUNCTION cmp_i8 (x, y, size)
IMPLICIT NONE
INTEGER*8, DIMENSION (1:size), INTENT (IN) :: x, y
INTEGER*8, INTENT (IN) :: size
INTEGER*8 i
DO i = 1, size
IF (x (i) /= y (i)) THEN
PRINT "('[proc ', I3, ']: Value error ', I6, ' /= ', I6)", &
myproc, x (i), y (i)
cmp_i8 = -2
RETURN
END IF
END DO
cmp_i8 = 0
END FUNCTION cmp_i8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
INTEGER*8 FUNCTION cmp_r4 (x, y, size)
IMPLICIT NONE
REAL*4, DIMENSION (1:size), INTENT (IN) :: x, y
INTEGER*8, INTENT (IN) :: size
INTEGER*8 i
DO i = 1, size
IF (x (i) /= y (i)) THEN
PRINT "('[proc ', I3, ']: Value error ', F6.2, ' /= ', F6.2)", &
myproc, x (i), y (i)
cmp_r4 = -2
RETURN
END IF
END DO
cmp_r4 = 0
END FUNCTION cmp_r4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
INTEGER*8 FUNCTION cmp_r8 (x, y, size)
IMPLICIT NONE
REAL*8, DIMENSION (1:size), INTENT (IN) :: x, y
INTEGER*8, INTENT (IN) :: size
INTEGER*8 i
DO i = 1, size
IF (x (i) /= y (i)) THEN
PRINT "('[proc ', I3, ']: Value error ', F6.2, ' /= ', F6.2)", &
myproc, x (i), y (i)
cmp_r8 = -2
RETURN
END IF
END DO
cmp_r8 = 0
END FUNCTION cmp_r8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
INTEGER*8 FUNCTION cmp_string (x, y, size)
IMPLICIT NONE
CHARACTER (LEN=size), INTENT (IN) :: x, y
INTEGER*8, INTENT (IN) :: size
INTEGER*8 i
DO i = 1, size
IF (x /= y) THEN
PRINT "('[proc ', I3, ']: Value error ', A, ' /= ', A)", &
myproc, x, y
cmp_string = -2
RETURN
END IF
END DO
cmp_string = 0
END FUNCTION cmp_string
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
INTEGER*8 FUNCTION read_file_attribs (file, myproc, num_procs)
IMPLICIT NONE
INTEGER*8, INTENT(IN) :: file
INTEGER, INTENT(IN) :: myproc
INTEGER, INTENT(IN) :: num_procs
INCLUDE 'H5hutF.h'
INTEGER*8 :: num_file_attribs
INTEGER*8 :: idx
CHARACTER(LEN=128) :: name
INTEGER*8 :: type
INTEGER*8 :: num_elems
INTEGER*8 :: h5_err
INTEGER*4, ALLOCATABLE :: i4 (:)
INTEGER*8, ALLOCATABLE :: i8 (:)
REAL*4, ALLOCATABLE :: r4 (:)
REAL*8, ALLOCATABLE :: r8 (:)
CHARACTER (LEN=H5_MAX_NAME_LEN) :: str
num_file_attribs = h5_getnfileattribs (file)
IF (num_file_attribs == H5_FAILURE) THEN
PRINT "('[proc ', I3, ']: Cannot read number of file attributes ...')", myproc
read_file_attribs = h5_err
RETURN
END IF
PRINT "('[proc ', I3, ']: Number of file attributes: ', I3)", myproc, num_file_attribs
DO idx = 1, num_file_attribs
h5_err = h5_getfileattribinfo (file, idx, name, type, num_elems)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Cannot get info about step attribute ', I2)", myproc, idx
RETURN
END IF
SELECT CASE (type)
CASE (H5_INT32_T)
PRINT "('[proc ', I3, ']: Reading file attribute of type H5_INT32_T ...')", myproc
ALLOCATE (i4 (num_elems))
h5_err = h5_readfileattrib_i4 (file, name, i4)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading attribute')", myproc
read_file_attribs = h5_err
RETURN
END IF
h5_err = cmp_i4 (i4, i4_attrib, num_elems)
IF (h5_err < 0) THEN
read_file_attribs = h5_err
RETURN
END IF
CASE (H5_INT64_T)
PRINT "('[proc ', I3, ']: Reading file attribute of type H5_INT64_T ...')", myproc
ALLOCATE (i8 (num_elems))
h5_err = h5_readfileattrib_i8 (file, name, i8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading attribute')", myproc
read_file_attribs = h5_err
RETURN
END IF
h5_err = cmp_i8 (i8, i8_attrib, num_elems)
IF (h5_err < 0) THEN
read_file_attribs = h5_err
RETURN
END IF
CASE (H5_FLOAT32_T)
PRINT "('[proc ', I3, ']: Reading file attribute of type H5_FLOAT32_T ...')", myproc
ALLOCATE (r4 (num_elems))
h5_err = h5_readfileattrib_r4 (file, name, r4)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading attribute')", myproc
read_file_attribs = h5_err
RETURN
END IF
h5_err = cmp_r4 (r4, r4_attrib, num_elems)
IF (h5_err < 0) THEN
read_file_attribs = h5_err
RETURN
END IF
CASE (H5_FLOAT64_T)
PRINT "('[proc ', I3, ']: Reading file attribute of type H5_FLOAT64_T ...')", myproc
ALLOCATE (r8 (num_elems))
h5_err = h5_readfileattrib_r8 (file, name, r8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading attribute')", myproc
read_file_attribs = h5_err
RETURN
END IF
h5_err = cmp_r8 (r8, r8_attrib, num_elems)
IF (h5_err < 0) THEN
read_file_attribs = h5_err
RETURN
END IF
CASE (H5_STRING_T)
PRINT "('[proc ', I3, ']: Reading file attribute of type H5_STRING_T ...')", myproc
h5_err = h5_readfileattrib_string (file, name, str)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading attribute')", myproc
read_file_attribs = h5_err
RETURN
END IF
h5_err = cmp_string (str, string_attrib, H5_MAX_NAME_LEN)
IF (h5_err < 0) THEN
read_file_attribs = h5_err
RETURN
END IF
END SELECT
END DO
read_file_attribs = 0
END FUNCTION read_file_attribs
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
INTEGER*8 FUNCTION read_step_attribs (file, myproc, num_procs)
IMPLICIT NONE
INTEGER*8, INTENT(IN) :: file
INTEGER, INTENT(IN) :: myproc
INTEGER, INTENT(IN) :: num_procs
INCLUDE 'H5hutF.h'
INTEGER*8 :: num_step_attribs
INTEGER*8 :: idx
CHARACTER(LEN=128) :: name
INTEGER*8 :: type
INTEGER*8 :: num_elems
INTEGER*8 :: h5_err
INTEGER*4, ALLOCATABLE :: i4 (:)
INTEGER*8, ALLOCATABLE :: i8 (:)
REAL*4, ALLOCATABLE :: r4 (:)
REAL*8, ALLOCATABLE :: r8 (:)
CHARACTER (LEN=H5_MAX_NAME_LEN) :: str
num_step_attribs = h5_getnstepattribs (file)
IF (num_step_attribs == H5_FAILURE) THEN
PRINT "('[proc ', I3, ']: Cannot read number of step attributes ...')", myproc
read_step_attribs = h5_err
END IF
PRINT "('[proc ', I3, ']: Number of step attributes: ', I3)", myproc, num_step_attribs
DO idx = 1, num_step_attribs
h5_err = h5_getstepattribinfo (file, idx, name, type, num_elems)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Cannot get info about step attribute ', I2)", myproc, idx
RETURN
END IF
SELECT CASE (type)
CASE (H5_INT32_T)
PRINT "('[proc ', I3, ']: Reading step attribute of type H5_INT32_T ...')", myproc
ALLOCATE (i4 (num_elems))
h5_err = h5_readstepattrib_i4 (file, name, i4)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading attribute')", myproc
read_step_attribs = h5_err
RETURN
END IF
h5_err = cmp_i4 (i4, i4_attrib, num_elems)
IF (h5_err < 0) THEN
read_step_attribs = h5_err
RETURN
END IF
CASE (H5_INT64_T)
PRINT "('[proc ', I3, ']: Reading step attribute of type H5_INT64_T ...')", myproc
ALLOCATE (i8 (num_elems))
h5_err = h5_readstepattrib_i8 (file, name, i8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading attribute')", myproc
read_step_attribs = h5_err
RETURN
END IF
h5_err = cmp_i8 (i8, i8_attrib, num_elems)
IF (h5_err < 0) THEN
read_step_attribs = h5_err
RETURN
END IF
CASE (H5_FLOAT32_T)
PRINT "('[proc ', I3, ']: Reading step attribute of type H5_FLOAT32_T ...')", myproc
ALLOCATE (r4 (num_elems))
h5_err = h5_readstepattrib_r4 (file, name, r4)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading attribute')", myproc
read_step_attribs = h5_err
RETURN
END IF
h5_err = cmp_r4 (r4, r4_attrib, num_elems)
IF (h5_err < 0) THEN
read_step_attribs = h5_err
RETURN
END IF
CASE (H5_FLOAT64_T)
PRINT "('[proc ', I3, ']: Reading step attribute of type H5_FLOAT64_T ...')", myproc
ALLOCATE (r8 (num_elems))
h5_err = h5_readstepattrib_r8 (file, name, r8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading attribute')", myproc
read_step_attribs = h5_err
RETURN
END IF
h5_err = cmp_r8 (r8, r8_attrib, num_elems)
IF (h5_err < 0) THEN
read_step_attribs = h5_err
RETURN
END IF
CASE (H5_STRING_T)
PRINT "('[proc ', I3, ']: Reading step attribute of type H5_STRING_T ...')", myproc
h5_err = h5_readstepattrib_string (file, name, str)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading attribute')", myproc
read_step_attribs = h5_err
RETURN
END IF
h5_err = cmp_string (str, string_attrib, H5_MAX_NAME_LEN)
IF (h5_err < 0) THEN
read_step_attribs = h5_err
RETURN
END IF
END SELECT
END DO
read_step_attribs = 0
END FUNCTION read_step_attribs
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
INTEGER*8 FUNCTION read_data (file, myproc, num_procs)
IMPLICIT NONE
INTEGER*8, INTENT(IN) :: file
INTEGER, INTENT(IN) :: myproc
INTEGER, INTENT(IN) :: num_procs
INCLUDE 'H5hutF.h'
INTEGER*8 :: h5_err = 0
INTEGER*8 :: num_points = 0
INTEGER*8 :: num = 0
INTEGER*8 :: num_points_total = 0
INTEGER*8 :: num_datasets = 0
INTEGER*8 :: offset = 0
INTEGER*8 :: idx = 0
INTEGER*8 :: step = 0
CHARACTER(LEN=128) :: name
INTEGER*8 :: type
REAL*8, ALLOCATABLE :: r8_data (:)
REAL*4, ALLOCATABLE :: r4_data (:)
INTEGER*8, ALLOCATABLE :: i8_data (:)
INTEGER*4, ALLOCATABLE :: i4_data (:)
REAL*8, ALLOCATABLE :: r8 (:)
REAL*4, ALLOCATABLE :: r4 (:)
INTEGER*8, ALLOCATABLE :: i8 (:)
INTEGER*4, ALLOCATABLE :: i4 (:)
num_datasets = h5pt_getndatasets (file)
IF (num_datasets < 0) THEN
PRINT "('[proc ', I3, ']: Cannot read number of datasets ...')", myproc
read_data = h5_err
RETURN
END IF
PRINT "('[proc ', I3, ']: Number of datasets: ', I3)", myproc, num_datasets
h5_err = h5pt_resetview (file)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Cannot reset view ...')", myproc
read_data = h5_err
RETURN
END IF
num_points_total = h5pt_getnpoints (file)
IF (num_points_total < 0) THEN
PRINT "('[proc ', I3, ']: Cannot read total number of points ...')", myproc
read_data = h5_err
RETURN
END IF
PRINT "('[proc ', I3, ']: Total number of points: ', I6)", myproc, num_points_total
! select subset
num_points = num_points_total / num_procs
offset = num_points * myproc + 1;
h5_err = h5pt_setview (file, offset, offset + num_points - 1)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Cannot set view ...')", myproc
read_data = h5_err
END IF
PRINT "('[proc ', I3, ']: View: ', I4, ':', I4)", myproc, offset, offset+num_points-1
ALLOCATE (r8_data (num_points))
ALLOCATE (r4_data (num_points))
ALLOCATE (i8_data (num_points))
ALLOCATE (i4_data (num_points))
ALLOCATE (r8 (num_points))
ALLOCATE (r4 (num_points))
ALLOCATE (i8 (num_points))
ALLOCATE (i4 (num_points))
step = h5_getstep (file)
offset = num_points * myproc
DO i = 1, num_points
r8_data (i) = REAL (i + offset + step)
r4_data (i) = REAL (i + offset + step)
i8_data (i) = i + offset + step
i4_data (i) = i + offset + step
ENDDO
DO idx = 1, num_datasets
h5_err = h5pt_getdatasetinfo (file, idx, name, type, num)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Cannot get info about datset ', I2)", myproc, idx
END IF
SELECT CASE (type)
CASE (H5_INT32_T)
PRINT "('[proc ', I3, ']: Reading dataset of type H5_INT32_T ...')", myproc
h5_err = h5pt_readdata_i4 (file, name, i4)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading datset')", myproc
read_data = h5_err
RETURN
END IF
h5_err = cmp_i4 (i4, i4_data, num_points)
IF (h5_err < 0) THEN
read_data = h5_err
RETURN
END IF
CASE (H5_INT64_T)
PRINT "('[proc ', I3, ']: Reading dataset of type H5_INT64_T ...')", myproc
h5_err = h5pt_readdata_i8 (file, name, i8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading datset')", myproc
read_data = h5_err
RETURN
END IF
h5_err = cmp_i8 (i8, i8_data, num_points)
IF (h5_err < 0) THEN
read_data = h5_err
RETURN
END IF
CASE (H5_FLOAT32_T)
PRINT "('[proc ', I3, ']: Reading dataset of type H5_FLOAT32_T ...')", myproc
h5_err = h5pt_readdata_r4 (file, name, r4)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading datset')", myproc
read_data = h5_err
RETURN
END IF
h5_err = cmp_r4 (r4, r4_data, num_points)
IF (h5_err < 0) THEN
read_data = h5_err
RETURN
END IF
CASE (H5_FLOAT64_T)
PRINT "('[proc ', I3, ']: Reading dataset of type H5_FLOAT64_T ...')", myproc
h5_err = h5pt_readdata_r8 (file, name, r8)
IF (h5_err < 0) THEN
PRINT "('[proc ', I3, ']: Error reading datset')", myproc
read_data = h5_err
RETURN
END IF
h5_err = cmp_r8 (r8, r8_data, num_points)
IF (h5_err < 0) THEN
read_data = h5_err
RETURN
END IF
END SELECT
END DO
read_data = 0
END FUNCTION read_data
END PROGRAM