1 #include <mpi.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <unistd.h> 5 #include <cassert> 6 #include "phiostats.h" 7 #include "phIO.h" 8 #include "phstream.h" //for makeRStream and makeGRStream 9 #include "syncio.h" 10 #include "posixio.h" 11 #include "streamio.h" 12 13 int main(int argc, char* argv[]) { 14 MPI_Init(&argc,&argv); 15 int rank; 16 MPI_Comm_rank(MPI_COMM_WORLD, &rank); 17 int size; 18 MPI_Comm_size(MPI_COMM_WORLD, &size); 19 if( argc != 2 ) { 20 fprintf(stderr, "Usage: %s <numSyncFiles>\n",argv[0]); 21 MPI_Finalize(); 22 return 1; 23 } 24 const char* phrase = "number of fishes"; 25 const char* type = "double"; 26 const char* iotype = "binary"; 27 int zero = 0; 28 int one = 1; 29 int numFish = 0; 30 double fishWeight = 1.23; 31 int nfiles = 1; 32 int ppf = size/nfiles; 33 const char* filename[2] = {"water-dat.", "water.dat."}; 34 rstream rs = makeRStream(); 35 phio_fp file[3]; 36 const char* modes[3]={"syncio", "posixio", "streamio"}; 37 syncio_setup_write(nfiles, one, ppf, &(file[0])); 38 posixio_setup(&(file[1]), 'w'); 39 streamio_setup_r(&(file[2]), rs, 'w'); 40 fprintf(stderr, "%s\n" ,"Outside loop 1.0"); 41 for(int i=0; i<3; i++) { 42 fprintf(stderr, "%s\n" ,"Within the i loop"); 43 if(!rank) fprintf(stderr, "%s\n", modes[i]); 44 fprintf(stderr, "%s\n" ,"Before phastaio"); 45 phastaio_initStats(); 46 fprintf(stderr, "%s\n" ,"Opening files with ", filename[i], file[i] ); 47 phio_openfile(filename[i], file[i]); 48 fprintf(stderr, "%s\n" ,"Entering for loop for ", atoi(argv[1]) ); 49 // const char* str = "Number of times "+ nfiles ; 50 for (int j = 0; j < 2 ; j++) { 51 fprintf(stderr,"%s\n", "Inside loop"); 52 //fprintf(stderr,"%d\n",atoi(argv[1])); 53 const char* str = "Number of times " +j; 54 fprintf(stderr,"%s\n", "Writing the header time - " ); 55 fprintf(stderr,"%s\n","Printing the int zero"); 56 fprintf(stderr,"%d\n",zero); 57 fprintf(stderr,"%s\n","Printing the int one"); 58 fprintf(stderr,"%d\n",one); 59 fprintf(stderr,"%s\n","Printing the file[i]"); 60 fprintf(stderr,"%s\n",file[i] ); 61 fprintf(stderr,"%s\n","Should have printed the file" ); 62 fprintf(stderr,"%s\n","Printing the const char type, this is set to double"); 63 fprintf(stderr,"%s\n",type); 64 fprintf(stderr,"%s\n","Printing the const char iotype, this is set to binary"); 65 fprintf(stderr,"%s\n",iotype); 66 fprintf(stderr,"%s\n","Opening the file" ); 67 phio_writeheader(file[i], str, &zero, &one, &zero, type, iotype); 68 fprintf(stderr,"%s\n","Printing the created string after writing the header "); 69 fprintf(stderr,"%s\n",str ); 70 fprintf(stderr,"%s\n","Printing the loop number" ); 71 fprintf(stderr,"%d\n",j ); 72 fprintf(stderr,"%s\n", "Writing the data block time - "); 73 // fprintf(stderr,"%d\n",j ); 74 phio_writedatablock(file[i], str, &fishWeight, &zero, type, iotype); 75 fprintf(stderr,"%s\n","Printing the file[i] after writing the data block" ); 76 fprintf(stderr,"%s\n",file[i] ); 77 fprintf(stderr,"%s\n","Printing the string that has been created " ); 78 fprintf(stderr,"%s\n",str ); 79 } 80 phio_closefile(file[i]); 81 phastaio_printStats(); 82 } 83 syncio_setup_read(nfiles, &(file[0])); 84 posixio_setup(&(file[1]), 'r'); 85 streamio_setup_r(&(file[2]), rs, 'r'); 86 for(int i=0; i<3; i++) { 87 if(!rank) fprintf(stderr, "%s\n", modes[i]); 88 phastaio_initStats(); 89 phio_openfile(filename[i], file[i]); 90 //Str was added 91 // const char* str = "Number of times "+ nfiles ; 92 // for (int j = 0; j < nfiles ; j++) { 93 phio_readheader(file[i], phrase, &numFish, &one, type, iotype); 94 // phio_readheader(file[i], str, &numFish, &one, type, iotype); 95 //Changing argument from file[i] to file[j] 96 assert(!numFish); 97 phio_readdatablock(file[i], phrase, &fishWeight, &numFish, type, iotype); 98 // phio_readdatablock(file[i], str, &fishWeight, &numFish, type, iotype); 99 assert(fishWeight == 1.23); 100 phio_closefile(file[i]); 101 phastaio_printStats(); 102 } 103 MPI_Finalize(); 104 return 0; 105 } 106