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
main(int argc,char * argv[])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
25 const char* phrase = "number of fishes";
26 const char* type = "double";
27 const char* iotype = "binary";
28 double blockArray[4] = {2.0,4.0,8.0,16.0};
29 int blockEntries = 4;
30 int one = 1;
31 int nfields = 2;
32 int numFish = 0;
33 double fishWeight = 1.23;
34 int nfiles = 1;
35 int ppf = size/nfiles;
36 const char* filename[3] = {"water.dat.", "water.","water-dat."};
37 rstream rs = makeRStream();
38 phio_fp file[3];
39 const char* modes[3]={"syncio","posixio","streamio"};
40 syncio_setup_write(nfiles, nfields, ppf, &(file[0]));
41 posixio_setup(&(file[1]), 'w');
42 streamio_setup_r(&(file[2]), rs, 'w');
43 for(int i=0; i<3; i++) {
44 if(!rank) fprintf(stderr, "%s\n", modes[i]);
45 phastaio_initStats();
46 phio_openfile(filename[i], file[i]);
47 char str [50];
48 int n;
49 for (int j = 0; j < 2 ; j++) {
50 n = sprintf(str, " Number of times %d ", j);
51 assert(n);
52 phio_writeheader(file[i], str, &blockEntries, &one, &blockEntries, type, iotype);
53 phio_writedatablock(file[i], str, blockArray, &blockEntries, type, iotype);
54 }
55 phio_closefile(file[i]);
56 phastaio_printStats();
57 }
58 syncio_setup_read(nfiles, &(file[0]));
59 posixio_setup(&(file[1]), 'r');
60 streamio_setup_r(&(file[2]), rs, 'r');
61 for(int i=0; i<3; i++) {
62 if(!rank) fprintf(stderr, "%s\n", modes[i]);
63 phastaio_initStats();
64 phio_openfile(filename[i], file[i]);
65 phio_readheader(file[i], phrase, &numFish, &one, type, iotype);
66 assert(!numFish);
67 phio_readdatablock(file[i], phrase, &fishWeight, &numFish, type, iotype);
68 assert(fishWeight == 1.23);
69 phio_closefile(file[i]);
70 phastaio_printStats();
71 }
72 MPI_Finalize();
73 return 0;
74 }
75