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