156813794SCameron Smith #include <mpi.h> 256813794SCameron Smith #include <stdio.h> 356813794SCameron Smith #include <stdlib.h> 456813794SCameron Smith #include <unistd.h> 556813794SCameron Smith #include <cassert> 656813794SCameron Smith #include "phIO.h" 756813794SCameron Smith #include "phstream.h" //for makeRStream and makeGRStream 856813794SCameron Smith #include "syncio.h" 956813794SCameron Smith #include "posixio.h" 1056813794SCameron Smith #include "streamio.h" 1156813794SCameron Smith 1256813794SCameron Smith int main(int argc, char* argv[]) { 1356813794SCameron Smith MPI_Init(&argc,&argv); 1456813794SCameron Smith int rank; 1556813794SCameron Smith MPI_Comm_rank(MPI_COMM_WORLD, &rank); 1656813794SCameron Smith int size; 1756813794SCameron Smith MPI_Comm_size(MPI_COMM_WORLD, &size); 1856813794SCameron Smith if( argc != 2 ) { 1956813794SCameron Smith fprintf(stderr, "Usage: %s <numSyncFiles>\n",argv[0]); 2056813794SCameron Smith MPI_Finalize(); 2156813794SCameron Smith return 1; 2256813794SCameron Smith } 2356813794SCameron Smith const char* phrase = "number of fishes"; 2456813794SCameron Smith const char* type = "double"; 2556813794SCameron Smith const char* iotype = "binary"; 2656813794SCameron Smith int zero = 0; 2756813794SCameron Smith int one = 1; 2856813794SCameron Smith int numFish = 0; 2956813794SCameron Smith double fishWeight = 1.23; 3056813794SCameron Smith int nfiles = atoi(argv[1]); 3156813794SCameron Smith int ppf = size/nfiles; 3256813794SCameron Smith const char* filename[2] = {"water-dat.", "water.dat."}; 3356813794SCameron Smith rstream rs = makeRStream(); 3456813794SCameron Smith phio_fp file[3]; 35*3fa9f015SCameron Smith const char* modes[3]={"syncio", "posixio", "streamio"}; 3656813794SCameron Smith syncio_setup_write(nfiles, one, ppf, &(file[0])); 3756813794SCameron Smith posixio_setup(&(file[1]), 'w'); 3888262674SCameron Smith streamio_setup_r(&(file[2]), rs, 'w'); 390d3dac81SCameron Smith for(int i=0; i<3; i++) { 40*3fa9f015SCameron Smith if(!rank) fprintf(stderr, "%s\n", modes[i]); 41*3fa9f015SCameron Smith phio_initStats(); 4256813794SCameron Smith phio_openfile(filename[i], file[i]); 4356813794SCameron Smith phio_writeheader(file[i], phrase, &zero, &one, &zero, type, iotype); 4456813794SCameron Smith phio_writedatablock(file[i], phrase, &fishWeight, &zero, type, iotype); 4556813794SCameron Smith phio_closefile(file[i]); 46*3fa9f015SCameron Smith phio_printStats(); 4756813794SCameron Smith } 4856813794SCameron Smith syncio_setup_read(nfiles, &(file[0])); 4956813794SCameron Smith posixio_setup(&(file[1]), 'r'); 5088262674SCameron Smith streamio_setup_r(&(file[2]), rs, 'r'); 510d3dac81SCameron Smith for(int i=0; i<3; i++) { 52*3fa9f015SCameron Smith if(!rank) fprintf(stderr, "%s\n", modes[i]); 53*3fa9f015SCameron Smith phio_initStats(); 5456813794SCameron Smith phio_openfile(filename[i], file[i]); 5556813794SCameron Smith phio_readheader(file[i], phrase, &numFish, &one, type, iotype); 5656813794SCameron Smith assert(!numFish); 5756813794SCameron Smith phio_readdatablock(file[i], phrase, &fishWeight, &numFish, type, iotype); 5856813794SCameron Smith assert(fishWeight == 1.23); 5956813794SCameron Smith phio_closefile(file[i]); 60*3fa9f015SCameron Smith phio_printStats(); 6156813794SCameron Smith } 6256813794SCameron Smith MPI_Finalize(); 6356813794SCameron Smith return 0; 6456813794SCameron Smith } 65