1 #include <stdlib.h> 2 #include <FCMangle.h> 3 #include <new_interface.h> 4 #include <stdio.h> 5 #include <string.h> //memset 6 #include <assert.h> 7 #include "common_c.h" 8 #include "phastaIO.h" 9 #include "phIO.h" 10 #include "setsyncioparam.h" 11 12 /* 13 void 14 read_d2wall( int* pid, 15 int* numnp, 16 double* array1 ) { 17 18 // time_t timenow = time ( &timenow); 19 int isize, nitems; 20 int iarray[10]; 21 22 //MPI_Barrier(MPI_COMM_WORLD); 23 24 /////////////////////////////// Start of writing using new-lib //////////////////////////// 25 26 int nfiles; 27 int nfields; 28 int numparts; 29 int irank; 30 int nprocs; 31 32 // First, count the number of fields to write and store the result in 33 //countfieldstowriterestart(); 34 35 // Retrieve and compute the parameters required for SyncIO 36 nfiles = outpar.nsynciofiles; 37 // nfields = 1; //outpar.nsynciofieldswriterestart; // Only the distance to the walls in d2wall 38 numparts = workfc.numpe; 39 irank = *pid; // workfc.myrank; 40 nprocs = workfc.numpe; 41 int nppf = numparts/nfiles; 42 int GPID; 43 44 // Calculate number of parts each proc deal with and where it start and end ... 45 int nppp = numparts/nprocs;// nppp : Number of parts per proc ... 46 int startpart = irank * nppp +1;// Part id from which I (myrank) start ... 47 int endpart = startpart + nppp - 1;// Part id to which I (myrank) end ... 48 49 int descriptor; 50 char filename[255],path[255],fieldtag_s[255]; 51 bzero((void*)filename,255); 52 bzero((void*)fieldtag_s,255); 53 54 sprintf(filename,"d2wall.%d",((int)(irank/(nprocs/nfiles))+1)); 55 56 queryphmpiio(filename, &nfields, &nppf); 57 58 initphmpiio(&nfields, &nppf, &nfiles, &f_descriptor, "read"); 59 60 if (irank==0) { 61 printf("Filename is %s \n",filename); 62 } 63 openfile(filename, "read", &f_descriptor); 64 65 field_flag=0; 66 67 int i; 68 for ( i = 0; i < nppp; i++) { //This loop is useful only if several parts per processor 69 // GPID : global part id, corresponds to rank ... 70 // e.g : (in this example) 71 // proc 0 : 1--4 72 // proc 1 : 5--8 ... 73 GPID = startpart + i; 74 75 // Write solution field ... 76 sprintf(fieldtag_s,"d2wall@%d",GPID); 77 78 nitems = 2; 79 readheader( &f_descriptor, fieldtag_s, (void*)iarray, &nitems, "double", phasta_iotype); 80 //iarray[ 0 ] = (*numnp); What we should get from readheader 81 //iarray[ 1 ] = 1; 82 83 if (iarray[0] != (*numnp)) { 84 printf("ERROR - numnp in d2wall.dat not coherent %d %d/n", iarray[0], *numnp); 85 } 86 87 isize = (*numnp); 88 readdatablock( &f_descriptor, fieldtag_s, (void*)(array1), &isize, "double", phasta_iotype ); 89 90 } 91 field_flag++; 92 93 if (field_flag==1){ 94 95 closefile(&f_descriptor, "read"); 96 97 finalizephmpiio(&f_descriptor); 98 99 if (irank==0) { 100 printf("\n"); 101 } 102 } 103 } 104 */ 105 106 107 void 108 read_d2wall( int* pid, 109 int* numnp, 110 double* array1, 111 int* foundd2wall ) { 112 113 // time_t timenow = time ( &timenow); 114 115 int isize, nitems; 116 int iarray[10]; 117 int j; 118 for ( j = 0; j < 10; j++) { 119 //Initialize iarray to 0 so that we can assess the result of readheader 120 iarray[j] = 0; 121 } 122 123 int nfiles; 124 int nfields; 125 int numparts; 126 int irank; 127 int nprocs; 128 129 // Retrieve and compute the parameters required for SyncIO 130 nfiles = outpar.nsynciofiles; 131 numparts = workfc.numpe; 132 irank = *pid; // workfc.myrank; 133 nprocs = workfc.numpe; 134 135 // Calculate number of parts each proc deal with and where it start and end ... 136 int nppp = numparts/nprocs;// nppp : Number of parts per proc ... 137 assert(nppp==1); 138 int startpart = irank * nppp +1;// Part id from which I (myrank) start ... 139 int endpart = startpart + nppp - 1;// Part id to which I (myrank) end ... 140 141 phio_fp handle; 142 char filename[255],path[255]; 143 memset((void*)filename,0,255); 144 *foundd2wall = 0; 145 //////////////////////////////////////////////////// 146 // First we try to read dwal from the restart files. 147 //////////////////////////////////////////////////// 148 149 if ( nfiles == 0 ) { 150 sprintf(filename,"restart.%d.", timdat.lstep); 151 } 152 else { 153 sprintf(filename,"restart-dat.%d.", timdat.lstep); 154 } 155 phio_openfile_read(filename, &nfiles, &handle); 156 157 int i; 158 for ( i = 0; i < nppp; i++) { //This loop is useful only if several parts per processor 159 nitems = 2; 160 phio_readheader(handle, "dwal", (void*)iarray, &nitems, "double", phasta_iotype); 161 //iarray[ 0 ] = (*numnp); What we should get from readheader 162 //iarray[ 1 ] = 1; 163 164 if (iarray[0] == (*numnp)) { 165 if (irank==0) { 166 printf("d2wall field found in %s\n",filename); 167 } 168 *foundd2wall = 1; 169 isize = (*numnp); 170 phio_readdatablock(handle, "dwal", (void*)(array1), &isize, "double", phasta_iotype ); 171 } 172 else { //d2wall fields was not found in the restart file 173 *foundd2wall = 0; 174 if (irank==0) { 175 printf("d2wall field not found in %s - trying d2wall files now\n",filename); 176 } 177 } 178 } 179 phio_closefile_read(handle); 180 181 182 if (irank==0) { 183 printf("\n"); 184 } 185 } 186