[300] | 1 | |
---|
[591] | 2 | #include "xios_spl.hpp" |
---|
[300] | 3 | #include "cxios.hpp" |
---|
[342] | 4 | #include "client.hpp" |
---|
| 5 | #include "server.hpp" |
---|
[346] | 6 | #include "xml_parser.hpp" |
---|
[300] | 7 | #include <boost/functional/hash.hpp> |
---|
[382] | 8 | #include "mpi.hpp" |
---|
[400] | 9 | #include "memory.hpp" |
---|
| 10 | #include <new> |
---|
[401] | 11 | #include "memtrack.hpp" |
---|
[697] | 12 | #include "registry.hpp" |
---|
[1328] | 13 | using namespace ep_lib; |
---|
[300] | 14 | |
---|
[335] | 15 | namespace xios |
---|
[300] | 16 | { |
---|
[1331] | 17 | const string CXios::rootFile="./iodef.xml" ; |
---|
| 18 | const string CXios::xiosCodeId="xios.x" ; |
---|
| 19 | const string CXios::clientFile="./xios_client"; |
---|
| 20 | const string CXios::serverFile="./xios_server"; |
---|
[490] | 21 | |
---|
[300] | 22 | bool CXios::isClient ; |
---|
| 23 | bool CXios::isServer ; |
---|
| 24 | MPI_Comm CXios::globalComm ; |
---|
| 25 | bool CXios::usingOasis ; |
---|
[491] | 26 | bool CXios::usingServer = false; |
---|
[718] | 27 | double CXios::bufferSizeFactor = 1.0; |
---|
| 28 | const double CXios::defaultBufferSizeFactor = 1.0; |
---|
[719] | 29 | StdSize CXios::minBufferSize = 1024 * sizeof(double); |
---|
[523] | 30 | bool CXios::printLogs2Files; |
---|
[511] | 31 | bool CXios::isOptPerformance = true; |
---|
[697] | 32 | CRegistry* CXios::globalRegistry = 0; |
---|
[1029] | 33 | double CXios::recvFieldTimeout = 10.0; |
---|
[490] | 34 | |
---|
[512] | 35 | //! Parse configuration file and create some objects from it |
---|
[300] | 36 | void CXios::initialize() |
---|
| 37 | { |
---|
[400] | 38 | set_new_handler(noMemory); |
---|
[1331] | 39 | int tmp_rank; |
---|
| 40 | MPI_Comm_rank(MPI_COMM_WORLD, &tmp_rank); |
---|
| 41 | #pragma omp critical |
---|
| 42 | { |
---|
| 43 | std::cout<<"thread "<<tmp_rank<<"("<<omp_get_thread_num()<<")"<<" parsing rootfile"<<std::endl; |
---|
| 44 | parseFile(rootFile); |
---|
| 45 | std::cout<<"thread "<<tmp_rank<<"("<<omp_get_thread_num()<<")"<<" parsed rootfile"<<std::endl; |
---|
| 46 | } |
---|
| 47 | #pragma omp barrier |
---|
[511] | 48 | parseXiosConfig(); |
---|
| 49 | } |
---|
| 50 | |
---|
[512] | 51 | /*! |
---|
| 52 | \brief Parse xios part of configuration file (.iodef.xml) |
---|
| 53 | Both client and server need information returned from this function |
---|
| 54 | */ |
---|
[511] | 55 | void CXios::parseXiosConfig() |
---|
| 56 | { |
---|
[311] | 57 | usingOasis=getin<bool>("using_oasis",false) ; |
---|
[506] | 58 | usingServer=getin<bool>("using_server",false) ; |
---|
[311] | 59 | info.setLevel(getin<int>("info_level",0)) ; |
---|
[512] | 60 | report.setLevel(getin<int>("info_level",50)); |
---|
[523] | 61 | printLogs2Files=getin<bool>("print_file",false); |
---|
[512] | 62 | |
---|
[511] | 63 | StdString bufMemory("memory"); |
---|
| 64 | StdString bufPerformance("performance"); |
---|
| 65 | StdString bufOpt = getin<StdString>("optimal_buffer_size", bufPerformance); |
---|
| 66 | std::transform(bufOpt.begin(), bufOpt.end(), bufOpt.begin(), ::tolower); |
---|
| 67 | if (0 == bufOpt.compare(bufMemory)) isOptPerformance = false; |
---|
| 68 | else if (0 != bufOpt.compare(bufPerformance)) |
---|
| 69 | { |
---|
| 70 | ERROR("CXios::parseXiosConfig()", << "optimal_buffer_size must be memory or performance "<< endl ); |
---|
| 71 | } |
---|
| 72 | |
---|
[718] | 73 | bufferSizeFactor = getin<double>("buffer_size_factor", defaultBufferSizeFactor); |
---|
[719] | 74 | minBufferSize = getin<int>("min_buffer_size", 1024 * sizeof(double)); |
---|
[1029] | 75 | recvFieldTimeout = getin<double>("recv_field_timeout", 10.0); |
---|
| 76 | if (recvFieldTimeout < 0.0) |
---|
| 77 | ERROR("CXios::parseXiosConfig()", "recv_field_timeout cannot be negative."); |
---|
[718] | 78 | |
---|
[1328] | 79 | //globalComm=MPI_COMM_WORLD ; |
---|
[1134] | 80 | int num_ep; |
---|
| 81 | if(isClient) |
---|
| 82 | { |
---|
| 83 | num_ep = omp_get_num_threads(); |
---|
| 84 | } |
---|
[1328] | 85 | |
---|
[1134] | 86 | if(isServer) |
---|
| 87 | { |
---|
[1331] | 88 | num_ep = 1; |
---|
[1134] | 89 | } |
---|
[1328] | 90 | |
---|
[1134] | 91 | MPI_Info info; |
---|
| 92 | #pragma omp master |
---|
| 93 | { |
---|
| 94 | MPI_Comm *ep_comm; |
---|
[1355] | 95 | MPI_Comm_create_endpoints(MPI_COMM_WORLD.mpi_comm, num_ep, info, ep_comm); // servers should reach here too. |
---|
[1134] | 96 | passage = ep_comm; |
---|
| 97 | } |
---|
[1328] | 98 | |
---|
| 99 | #pragma omp barrier |
---|
[1134] | 100 | |
---|
[1328] | 101 | |
---|
[1134] | 102 | CXios::globalComm = passage[omp_get_thread_num()]; |
---|
[300] | 103 | } |
---|
| 104 | |
---|
[512] | 105 | /*! |
---|
| 106 | Initialize client |
---|
| 107 | \param [in] codeId identity of context |
---|
| 108 | \param [in] localComm local communicator |
---|
| 109 | \param [in/out] returnComm communicator corresponding to group of client with same codeId |
---|
| 110 | */ |
---|
[300] | 111 | void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm) |
---|
| 112 | { |
---|
[1134] | 113 | isClient = true; |
---|
| 114 | |
---|
[300] | 115 | initialize() ; |
---|
[490] | 116 | |
---|
[1134] | 117 | CClient::initialize(codeId,localComm,returnComm) ; |
---|
[697] | 118 | if (CClient::getRank()==0) globalRegistry = new CRegistry(returnComm) ; |
---|
[491] | 119 | |
---|
[956] | 120 | // If there are no server processes then we are in attached mode |
---|
| 121 | // and the clients are also servers |
---|
| 122 | isServer = !usingServer; |
---|
[490] | 123 | |
---|
[523] | 124 | if (printLogs2Files) |
---|
| 125 | { |
---|
[1342] | 126 | #pragma omp critical |
---|
[499] | 127 | CClient::openInfoStream(clientFile); |
---|
[523] | 128 | CClient::openErrorStream(clientFile); |
---|
| 129 | } |
---|
[490] | 130 | else |
---|
[523] | 131 | { |
---|
[490] | 132 | CClient::openInfoStream(); |
---|
[523] | 133 | CClient::openErrorStream(); |
---|
| 134 | } |
---|
[490] | 135 | } |
---|
[300] | 136 | |
---|
| 137 | void CXios::clientFinalize(void) |
---|
| 138 | { |
---|
[490] | 139 | CClient::finalize() ; |
---|
[697] | 140 | if (CClient::getRank()==0) |
---|
| 141 | { |
---|
[1342] | 142 | #pragma omp critical (_output) |
---|
[697] | 143 | info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ; |
---|
| 144 | globalRegistry->toFile("xios_registry.bin") ; |
---|
| 145 | delete globalRegistry ; |
---|
| 146 | } |
---|
[1160] | 147 | |
---|
[401] | 148 | #ifdef XIOS_MEMTRACK |
---|
[1156] | 149 | |
---|
| 150 | #ifdef XIOS_MEMTRACK_LIGHT |
---|
| 151 | report(10) << " Memory report : current memory used by XIOS : "<< MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 152 | report(10) << " Memory report : maximum memory used by XIOS : "<< MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 153 | #endif |
---|
| 154 | |
---|
| 155 | #ifdef XIOS_MEMTRACK_FULL |
---|
[401] | 156 | MemTrack::TrackListMemoryUsage() ; |
---|
[490] | 157 | MemTrack::TrackDumpBlocks(); |
---|
[401] | 158 | #endif |
---|
[1161] | 159 | |
---|
[1205] | 160 | CClient::closeInfoStream(); |
---|
| 161 | |
---|
[1161] | 162 | #endif |
---|
[490] | 163 | } |
---|
| 164 | |
---|
[512] | 165 | //! Init server by parsing only xios part of config file |
---|
[509] | 166 | void CXios::initServer() |
---|
| 167 | { |
---|
| 168 | set_new_handler(noMemory); |
---|
| 169 | std::set<StdString> parseList; |
---|
| 170 | parseList.insert("xios"); |
---|
| 171 | xml::CXMLParser::ParseFile(rootFile, parseList); |
---|
[511] | 172 | parseXiosConfig(); |
---|
[509] | 173 | } |
---|
| 174 | |
---|
[512] | 175 | //! Initialize server then put it into listening state |
---|
[300] | 176 | void CXios::initServerSide(void) |
---|
| 177 | { |
---|
[1134] | 178 | |
---|
[956] | 179 | isClient = false; |
---|
| 180 | isServer = true; |
---|
[1134] | 181 | |
---|
| 182 | initServer(); |
---|
[1328] | 183 | |
---|
[491] | 184 | // Initialize all aspects MPI |
---|
[490] | 185 | CServer::initialize(); |
---|
[697] | 186 | if (CServer::getRank()==0) globalRegistry = new CRegistry(CServer::intraComm) ; |
---|
| 187 | |
---|
[523] | 188 | if (printLogs2Files) |
---|
| 189 | { |
---|
[499] | 190 | CServer::openInfoStream(serverFile); |
---|
[523] | 191 | CServer::openErrorStream(serverFile); |
---|
| 192 | } |
---|
[490] | 193 | else |
---|
[523] | 194 | { |
---|
[490] | 195 | CServer::openInfoStream(); |
---|
[523] | 196 | CServer::openErrorStream(); |
---|
| 197 | } |
---|
[490] | 198 | |
---|
[491] | 199 | // Enter the loop to listen message from Client |
---|
[490] | 200 | CServer::eventLoop(); |
---|
| 201 | |
---|
[491] | 202 | // Finalize |
---|
[697] | 203 | if (CServer::getRank()==0) |
---|
| 204 | { |
---|
| 205 | info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ; |
---|
| 206 | globalRegistry->toFile("xios_registry.bin") ; |
---|
| 207 | delete globalRegistry ; |
---|
| 208 | } |
---|
[1205] | 209 | CServer::finalize(); |
---|
[1134] | 210 | |
---|
[1205] | 211 | #ifdef XIOS_MEMTRACK |
---|
| 212 | |
---|
| 213 | #ifdef XIOS_MEMTRACK_LIGHT |
---|
| 214 | report(10) << " Memory report : current memory used by XIOS : "<< MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 215 | report(10) << " Memory report : maximum memory used by XIOS : "<< MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 216 | #endif |
---|
| 217 | |
---|
| 218 | #ifdef XIOS_MEMTRACK_FULL |
---|
| 219 | MemTrack::TrackListMemoryUsage() ; |
---|
| 220 | MemTrack::TrackDumpBlocks(); |
---|
| 221 | #endif |
---|
| 222 | #endif |
---|
[490] | 223 | CServer::closeInfoStream(); |
---|
| 224 | } |
---|
| 225 | |
---|
[512] | 226 | //! Parse configuration file |
---|
[346] | 227 | void CXios::parseFile(const string& filename) |
---|
| 228 | { |
---|
[490] | 229 | xml::CXMLParser::ParseFile(filename); |
---|
[346] | 230 | } |
---|
[491] | 231 | |
---|
[512] | 232 | //! Set using server |
---|
[491] | 233 | void CXios::setUsingServer() |
---|
| 234 | { |
---|
| 235 | usingServer = true; |
---|
| 236 | } |
---|
| 237 | |
---|
[512] | 238 | //! Unset using server |
---|
[491] | 239 | void CXios::setNotUsingServer() |
---|
| 240 | { |
---|
| 241 | usingServer = false; |
---|
| 242 | } |
---|
[300] | 243 | } |
---|