5 #include <boost/functional/hash.hpp>
40 MPI_Initialized(&initialized) ;
49 if (localComm == MPI_COMM_NULL)
57 boost::hash<string> hashString ;
59 unsigned long hashClient=hashString(codeId) ;
61 unsigned long* hashAll ;
70 hashAll=
new unsigned long[size] ;
74 map<unsigned long, int> colors ;
75 map<unsigned long, int> leaders ;
77 for(i=0,c=0;i<size;i++)
79 if (colors.find(hashAll[i])==colors.end())
81 colors[hashAll[i]] =c ;
82 leaders[hashAll[i]]=i ;
89 for (i=0; i < size; ++i)
91 if (hashServer == hashAll[i])
98 myColor=colors[hashClient];
103 int clientLeader=leaders[hashClient] ;
105 int intraCommSize, intraCommRank ;
106 MPI_Comm_size(
intraComm,&intraCommSize) ;
107 MPI_Comm_rank(
intraComm,&intraCommRank) ;
108 info(50)<<
"intercommCreate::client "<<
rank_<<
" intraCommSize : "<<intraCommSize
109 <<
" intraCommRank :"<<intraCommRank<<
" clientLeader "<<
serverLeader<<endl ;
137 if (localComm == MPI_COMM_NULL)
175 idServer +=
"_server";
180 MPI_Comm contextInterComm ;
181 MPI_Comm_dup(contextComm,&contextInterComm) ;
185 context->
initClient(contextComm,contextInterComm, contextServer);
188 contextServer->
initServer(contextComm,contextInterComm, context);
197 int size,rank,globalRank ;
198 size_t message_size ;
200 MPI_Comm contextInterComm ;
202 MPI_Comm_size(contextComm,&size) ;
203 MPI_Comm_rank(contextComm,&rank) ;
205 if (rank!=0) globalRank=0 ;
208 msg<<idServer<<size<<globalRank ;
211 int messageSize=msg.
size() ;
212 char * buff =
new char[messageSize] ;
218 MPI_Intercomm_create(contextComm,0,
CXios::globalComm,serverLeader,10+globalRank,&contextInterComm) ;
219 info(10)<<
"Register new Context : "<<
id<<endl ;
221 MPI_Intercomm_merge(contextInterComm,0,&inter) ;
224 context->
initClient(contextComm,contextInterComm) ;
227 MPI_Comm_free(&inter);
240 bool oasisEnddef=CXios::getin<bool>(
"call_oasis_enddef",
true) ;
241 if (!oasisEnddef)
ERROR(
"void CClient::callOasisEnddef(void)", <<
"Function xios_oasis_enddef called but variable <call_oasis_enddef> is set to false."<<endl
242 <<
"Variable <call_oasis_enddef> must be set to true"<<endl) ;
280 MPI_Comm_free(&(*it));
290 else MPI_Finalize() ;
293 info(20) <<
"Client side context is finalized"<<endl ;
298 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 ;
301 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 ;
337 fileNameClient << fileName <<
"_" << std::setfill(
'0') << std::setw(numDigit) << rank << ext;
340 fileNameClient << fileName <<
"_" << std::setfill(
'0') << std::setw(numDigit) <<
getRank() << ext;
343 fb->open(fileNameClient.str().c_str(), std::ios::out);
345 ERROR(
"void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)",
346 << std::endl <<
"Can not open <" << fileNameClient.str() <<
"> file to write the client log(s).");
std::ofstream StdOFStream
static StdOFStream m_infoStream
static void initialize(const string &codeId, MPI_Comm &localComm, MPI_Comm &returnComm)
std::stringstream StdStringStream
static void openErrorStream()
Write the error log to standard error output.
void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext *cxtClient=0)
void oasis_finalize(void)
double getCumulatedTime(void)
static std::list< MPI_Comm > contextInterComms
void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext *cxtServer=0)
static void registerContext(const string &id, MPI_Comm contextComm)
static void closeErrorStream()
Close the error log file if it opens.
static bool usingServer
Using server (server mode)
void write2StdOut()
Write log into standard output.
static MPI_Comm globalComm
Global communicator.
static MPI_Comm & getInterComm()
static void setCurrent(const string &id)
Set context with an id be the current context.
void oasis_get_intercomm(MPI_Comm &comm_client_server, const std::string &server_id)
static void setNotUsingServer()
Setting xios NOT to use server mode.
CATCH CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar *scalarDestination, CScalar *scalarSource, CReduceScalarToScalar *algo ERROR)("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo)",<< "Operation must be defined."<< "Scalar source "<< scalarSource->getId()<< std::endl<< "Scalar destination "<< scalarDestination->getId())
static void openStream(const StdString &fileName, const StdString &ext, std::filebuf *fb)
Open a file specified by a suffix and an extension and use it for the given file buffer.
static CContext * create(const string &id="")
Create a context with specific id.
static string xiosCodeId
Identity for XIOS.
static void openInfoStream()
Write the info logs to standard output.
CLog error("error", cerr.rdbuf())
static int getRank()
Get global rank without oasis and current rank in model intraComm in case of oasis.
static bool isServer
Check if xios is server.
static bool usingOasis
Using Oasis.
static void finalize(void)
virtual size_t size(void) const
void oasis_init(const std::string &server_id)
static MPI_Comm interComm
void write2StdErr()
Write log into standard error output.
static void callOasisEnddef(void)
Send the order to the servers to call "oasis_enddef".
static CTimer & get(std::string name)
static void setUsingServer()
Setting xios to use server mode.
static MPI_Comm intraComm
static size_t maxRequestSize
static bool is_MPI_Initialized
void write2File(std::streambuf *sBuff)
Write log into a file with its streambuf.
static void closeInfoStream()
Close the info logs file if it opens.
static int rank_
Rank in model intraComm.
static StdOFStream m_errorStream
static std::string getAllCumulatedTime(void)
void oasis_get_localcomm(MPI_Comm &comm)