1*56813794SCameron Smith #include <mpi.h> 2*56813794SCameron Smith #include <stdio.h> 3*56813794SCameron Smith #include <stdlib.h> 4*56813794SCameron Smith #include <unistd.h> 5*56813794SCameron Smith #include <cassert> 6*56813794SCameron Smith #include "phIO.h" 7*56813794SCameron Smith #include "phstream.h" //for makeRStream and makeGRStream 8*56813794SCameron Smith #include "syncio.h" 9*56813794SCameron Smith #include "posixio.h" 10*56813794SCameron Smith #include "streamio.h" 11*56813794SCameron Smith 12*56813794SCameron Smith int main(int argc, char* argv[]) { 13*56813794SCameron Smith MPI_Init(&argc,&argv); 14*56813794SCameron Smith int rank; 15*56813794SCameron Smith MPI_Comm_rank(MPI_COMM_WORLD, &rank); 16*56813794SCameron Smith int size; 17*56813794SCameron Smith MPI_Comm_size(MPI_COMM_WORLD, &size); 18*56813794SCameron Smith if( argc != 2 ) { 19*56813794SCameron Smith fprintf(stderr, "Usage: %s <numSyncFiles>\n",argv[0]); 20*56813794SCameron Smith MPI_Finalize(); 21*56813794SCameron Smith return 1; 22*56813794SCameron Smith } 23*56813794SCameron Smith const char* phrase = "number of fishes"; 24*56813794SCameron Smith const char* type = "double"; 25*56813794SCameron Smith const char* iotype = "binary"; 26*56813794SCameron Smith int zero = 0; 27*56813794SCameron Smith int one = 1; 28*56813794SCameron Smith int numFish = 0; 29*56813794SCameron Smith double fishWeight = 1.23; 30*56813794SCameron Smith int nfiles = atoi(argv[1]); 31*56813794SCameron Smith int ppf = size/nfiles; 32*56813794SCameron Smith const char* filename[2] = {"water-dat.", "water.dat."}; 33*56813794SCameron Smith rstream rs = makeRStream(); 34*56813794SCameron Smith grstream grs = makeGRStream(); 35*56813794SCameron Smith phio_fp file[3]; 36*56813794SCameron Smith syncio_setup_write(nfiles, one, ppf, &(file[0])); 37*56813794SCameron Smith posixio_setup(&(file[1]), 'w'); 38*56813794SCameron Smith streamio_setup_write(&(file[2]), rs); 39*56813794SCameron Smith for(int i=0; i<2; i++) { 40*56813794SCameron Smith phio_openfile(filename[i], file[i]); 41*56813794SCameron Smith phio_writeheader(file[i], phrase, &zero, &one, &zero, type, iotype); 42*56813794SCameron Smith phio_writedatablock(file[i], phrase, &fishWeight, &zero, type, iotype); 43*56813794SCameron Smith phio_closefile(file[i]); 44*56813794SCameron Smith } 45*56813794SCameron Smith syncio_setup_read(nfiles, &(file[0])); 46*56813794SCameron Smith posixio_setup(&(file[1]), 'r'); 47*56813794SCameron Smith streamio_read_r(&(file[2]), rs); 48*56813794SCameron Smith for(int i=0; i<2; i++) { 49*56813794SCameron Smith phio_openfile(filename[i], file[i]); 50*56813794SCameron Smith phio_readheader(file[i], phrase, &numFish, &one, type, iotype); 51*56813794SCameron Smith assert(!numFish); 52*56813794SCameron Smith phio_readdatablock(file[i], phrase, &fishWeight, &numFish, type, iotype); 53*56813794SCameron Smith assert(fishWeight == 1.23); 54*56813794SCameron Smith phio_closefile(file[i]); 55*56813794SCameron Smith } 56*56813794SCameron Smith MPI_Finalize(); 57*56813794SCameron Smith return 0; 58*56813794SCameron Smith } 59