Changeset 1460 for XIOS/dev/branch_openmp/src/client.cpp
- Timestamp:
- 03/22/18 10:43:20 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/branch_openmp/src/client.cpp
r1374 r1460 22 22 int CClient::serverLeader ; 23 23 bool CClient::is_MPI_Initialized ; 24 int CClient::rank = INVALID_RANK;24 int CClient::rank_ = INVALID_RANK; 25 25 StdOFStream CClient::m_infoStream; 26 26 StdOFStream CClient::m_errorStream; … … 28 28 StdOFStream CClient::array_infoStream[16]; 29 29 30 void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm) 30 MPI_Comm& CClient::getInterComm(void) { return (interComm); } 31 32 ///--------------------------------------------------------------- 33 /*! 34 * \fn void CClient::initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm) 35 * Function creates intraComm (CClient::intraComm) for client group with id=codeId and interComm (CClient::interComm) between client and server groups. 36 * \param [in] codeId identity of context. 37 * \param [in/out] localComm local communicator. 38 * \param [in/out] returnComm (intra)communicator of client group. 39 */ 40 41 void CClient::initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm) 31 42 { 32 43 int initialized ; … … 34 45 if (initialized) is_MPI_Initialized=true ; 35 46 else is_MPI_Initialized=false ; 47 int rank ; 36 48 37 49 // don't use OASIS 38 50 if (!CXios::usingOasis) 39 51 { 40 // localComm doesn't given52 // localComm isn't given 41 53 if (localComm == MPI_COMM_NULL) 42 54 { … … 58 70 59 71 MPI_Comm_size(CXios::globalComm,&size) ; 60 MPI_Comm_rank(CXios::globalComm,&rank );72 MPI_Comm_rank(CXios::globalComm,&rank_); 61 73 62 74 hashAll=new unsigned long[size] ; … … 88 100 } 89 101 90 myColor=colors[hashClient] ; 91 92 MPI_Comm_split(CXios::globalComm,myColor,rank,&intraComm) ; 102 myColor=colors[hashClient]; 103 MPI_Comm_split(CXios::globalComm,myColor,rank_,&intraComm) ; 93 104 94 105 if (CXios::usingServer) … … 96 107 int clientLeader=leaders[hashClient] ; 97 108 serverLeader=leaders[hashServer] ; 98 99 109 int intraCommSize, intraCommRank ; 100 110 MPI_Comm_size(intraComm,&intraCommSize) ; … … 102 112 #pragma omp critical (_output) 103 113 { 104 info(50)<<"intercommCreate::client "<<rank<<" intraCommSize : "<<intraCommSize 105 <<" intraCommRank :"<<intraCommRank<<" serverLeader "<< serverLeader<<endl ; 106 } 107 MPI_Intercomm_create(intraComm,0,CXios::globalComm,serverLeader,0,&interComm) ; 114 info(50)<<"intercommCreate::client "<<rank_<<" intraCommSize : "<<intraCommSize 115 <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< serverLeader<<endl ; 116 } 117 MPI_Intercomm_create(intraComm, 0, CXios::globalComm, serverLeader, 0, &interComm) ; 118 //rank_ = intraCommRank; 108 119 } 109 120 else … … 128 139 } 129 140 // using OASIS 130 /*else131 { 132 // localComm doesn't given141 else 142 { 143 // localComm isn't given 133 144 if (localComm == MPI_COMM_NULL) 134 145 { … … 144 155 { 145 156 MPI_Status status ; 146 MPI_Comm_rank(intraComm,&rank ) ;157 MPI_Comm_rank(intraComm,&rank_) ; 147 158 148 159 oasis_get_intercomm(interComm,CXios::xiosCodeId) ; 149 if (rank ==0) MPI_Recv(&serverLeader,1, MPI_INT, 0, 0, interComm, &status) ;160 if (rank_==0) MPI_Recv(&serverLeader,1, MPI_INT, 0, 0, interComm, &status) ; 150 161 MPI_Bcast(&serverLeader,1,MPI_INT,0,intraComm) ; 151 152 162 } 153 163 else MPI_Comm_dup(intraComm,&interComm) ; 154 164 } 155 */ 165 156 166 MPI_Comm_dup(intraComm,&returnComm) ; 157 167 } 158 168 159 160 void CClient::registerContext(const string& id,MPI_Comm contextComm) 169 ///--------------------------------------------------------------- 170 /*! 171 * \fn void CClient::registerContext(const string& id, MPI_Comm contextComm) 172 * \brief Sends a request to create a context to server. Creates client/server contexts. 173 * \param [in] id id of context. 174 * \param [in] contextComm. 175 * Function is only called by client. 176 */ 177 void CClient::registerContext(const string& id, MPI_Comm contextComm) 161 178 { 162 179 CContext::setCurrent(id) ; … … 165 182 idServer += "_server"; 166 183 167 if (!CXios::isServer) 184 if (CXios::isServer && !context->hasServer) 185 // Attached mode 186 { 187 MPI_Comm contextInterComm ; 188 MPI_Comm_dup(contextComm,&contextInterComm) ; 189 CContext* contextServer = CContext::create(idServer); 190 191 // Firstly, initialize context on client side 192 context->initClient(contextComm,contextInterComm, contextServer); 193 194 // Secondly, initialize context on server side 195 contextServer->initServer(contextComm,contextInterComm, context); 196 197 // Finally, we should return current context to context client 198 CContext::setCurrent(id); 199 200 //contextInterComms.push_back(contextInterComm); 201 if(contextInterComms_ptr == NULL) contextInterComms_ptr = new std::list<MPI_Comm>; 202 contextInterComms_ptr->push_back(contextInterComm); 203 } 204 else 168 205 { 169 206 int size,rank,globalRank ; … … 177 214 if (rank!=0) globalRank=0 ; 178 215 179 180 216 CMessage msg ; 181 217 msg<<idServer<<size<<globalRank ; … … 189 225 MPI_Send((void*)buff,buffer.count(),MPI_CHAR,serverLeader,1,CXios::globalComm) ; 190 226 191 delete [] buff ;192 193 //MPI_Barrier(CXios::globalComm);194 195 227 MPI_Intercomm_create(contextComm,0,CXios::globalComm,serverLeader,10+globalRank,&contextInterComm) ; 196 228 #pragma omp critical (_output) 197 { 198 info(10)<<"Register new Context : "<<id<<endl ; 199 } 200 229 info(10)<<"Register new Context : "<<id<<endl ; 201 230 MPI_Comm inter ; 202 231 MPI_Intercomm_merge(contextInterComm,0,&inter) ; … … 208 237 if(contextInterComms_ptr == NULL) contextInterComms_ptr = new std::list<MPI_Comm>; 209 238 contextInterComms_ptr->push_back(contextInterComm); 239 210 240 MPI_Comm_free(&inter); 211 } 212 else 213 { 214 MPI_Comm contextInterComm ; 215 MPI_Comm_dup(contextComm,&contextInterComm) ; 216 CContext* contextServer = CContext::create(idServer); 217 218 // Firstly, initialize context on client side 219 context->initClient(contextComm,contextInterComm, contextServer); 220 221 // Secondly, initialize context on server side 222 contextServer->initServer(contextComm,contextInterComm, context); 223 224 // Finally, we should return current context to context client 225 CContext::setCurrent(id); 226 227 //contextInterComms.push_back(contextInterComm); 228 if(contextInterComms_ptr == NULL) contextInterComms_ptr = new std::list<MPI_Comm>; 229 contextInterComms_ptr->push_back(contextInterComm); 241 delete [] buff ; 242 230 243 } 231 244 } … … 264 277 #pragma omp critical (_output) 265 278 info(20) << "Client side context is finalized"<<endl ; 266 267 268 /*#pragma omp critical (_output) 279 280 #pragma omp critical (_output) 269 281 { 270 282 report(0) <<" Performance report : Whole time from XIOS init and finalize: "<< CTimer::get("XIOS init/finalize").getCumulatedTime()<<" s"<<endl ; … … 273 285 report(0)<< " Performance report : Ratio : "<< CTimer::get("Blocking time").getCumulatedTime()/CTimer::get("XIOS init/finalize").getCumulatedTime()*100.<<" %"<<endl ; 274 286 report(0)<< " Performance report : This ratio must be close to zero. Otherwise it may be usefull to increase buffer size or numbers of server"<<endl ; 287 // report(0)<< " Memory report : Current buffer_size : "<<CXios::bufferSize<<endl ; 275 288 report(0)<< " Memory report : Minimum buffer size required : " << CClientBuffer::maxRequestSize << " bytes" << endl ; 276 289 report(0)<< " Memory report : increasing it by a factor will increase performance, depending of the volume of data wrote in file at each time step of the file"<<endl ; 277 290 report(100)<<CTimer::getAllCumulatedTime()<<endl ; 278 } */291 } 279 292 } 280 293 294 /*! 295 * Return global rank without oasis and current rank in model intraComm in case of oasis 296 */ 281 297 int CClient::getRank() 282 298 { 283 return rank ;299 return rank_; 284 300 } 285 301 … … 297 313 int numDigit = 0; 298 314 int size = 0; 315 int rank; 299 316 MPI_Comm_size(CXios::globalComm, &size); 300 317 while (size) … … 304 321 } 305 322 306 fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ext; 323 if (CXios::usingOasis) 324 { 325 MPI_Comm_rank(CXios::globalComm,&rank); 326 fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << rank << ext; 327 } 328 else 329 fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ext; 330 331 307 332 fb->open(fileNameClient.str().c_str(), std::ios::out); 308 333 if (!fb->is_open())
Note: See TracChangeset
for help on using the changeset viewer.