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