1 #include "phIO.h" 2 #include "phComm.h" 3 #include <stdio.h> 4 #include <string.h> 5 #include <assert.h> 6 #include <phastaIO.h> 7 #include <sstream> 8 #include <string> 9 10 namespace { 11 std::string appendSync(const char* phrase) { 12 std::stringstream ss; 13 ss << phrase << "@" << phcomm_rank()+1 << "?"; 14 std::string s = ss.str(); 15 return s; 16 } 17 std::string appendColor(const char* phrase, int numFiles) { 18 const int color = computeColor(phcomm_rank(), phcomm_size(), numFiles); 19 std::stringstream ss; 20 ss << phrase << color+1; 21 std::string s = ss.str(); 22 return s; 23 } 24 } 25 26 void phio_readheader( 27 int* fileDescriptor, 28 const char keyphrase[], 29 void* valueArray, 30 int* nItems, 31 const char datatype[], 32 const char iotype[] ) { 33 std::string syncPhrase = appendSync(keyphrase); 34 readheader(fileDescriptor, syncPhrase.c_str(), 35 valueArray, nItems, datatype, iotype); 36 } 37 38 void phio_readdatablock( 39 int* fileDescriptor, 40 const char keyphrase[], 41 void* valueArray, 42 int* nItems, 43 const char datatype[], 44 const char iotype[] ) { 45 std::string syncPhrase = appendSync(keyphrase); 46 readdatablock(fileDescriptor, syncPhrase.c_str(), 47 valueArray, nItems, datatype, iotype); 48 } 49 50 void phio_openfile( 51 const char filename[], 52 const char mode[], 53 int* numFiles, 54 int* numFields, 55 int* numPPF, 56 int* fileDescriptor) { 57 std::string syncName = appendColor(filename, *numFiles); 58 int nfields = *numFields; 59 int nppf = *numPPF; 60 if( std::string(mode) == "read" ) 61 queryphmpiio(syncName.c_str(), &nfields, &nppf); 62 //TODO - define a good upper bound 63 assert(nfields > 0 && nfields < 1024); 64 assert(nppf > 0 && nppf < 1024); 65 initphmpiio(&nfields, &nppf, numFiles, fileDescriptor, mode); 66 openfile(syncName.c_str(), mode, fileDescriptor); 67 } 68 69 void phio_restartname(int* step, char* filename) { 70 std::stringstream ss; 71 ss << "restart-dat." << *step << '.'; 72 std::string s = ss.str(); 73 strcpy(filename, s.c_str()); 74 } 75