13 for(map<
string,pair<size_t,char*> >::const_iterator it=reg.
registry.begin() ; it!=reg.
registry.end() ; ++it)
15 char* buffer=
new char[it->second.first] ;
16 memcpy(buffer,it->second.second,it->second.first) ;
17 registry.insert(pair<
string, pair<size_t,char*> >(it->first, pair<size_t,char*>(it->second.first,buffer))) ;
24 for(map<
string,pair<size_t,char*> >::const_iterator it=
registry.begin() ; it!=
registry.end() ; ++it)
26 if (it->second.first>0)
delete[] it->second.second ;
33 const string key=
path+key_ ;
38 map<string,pair<size_t,char*> >::iterator it=
registry.find(key) ;
42 delete[] it->second.second ;
46 char* buffer=
new char[
size] ;
49 registry.insert(pair<
string, pair<size_t,char*> >(key, pair<size_t,char*>(size,buffer))) ;
55 const string key=
path+key_ ;
58 map<string,pair<size_t,char*> >::iterator it=
registry.find(key) ;
62 CBufferIn tmpBuff(it->second.second,it->second.first) ;
70 const string key=
path+key_ ;
71 map<string,pair<size_t,char*> >::const_iterator it=
registry.find(key) ;
72 if (it!=
registry.end())
return true ;
79 for(map<
string,pair<size_t,char*> >::const_iterator it=
registry.begin() ; it!=
registry.end() ; ++it)
81 buffer<<it->first<<it->second.first ;
82 if (!buffer.
put(it->second.second,it->second.first))
ERROR(
"bool CRegistry::toBuffer(CBufferOut& buffer) const)",
83 <<
"Not enough free space in buffer to queue the data.");
93 for(map<
string,pair<size_t,char*> >::const_iterator it=
registry.begin() ; it!=
registry.end() ; ++it)
100 ERROR(
"void CRegistry::fromString(const string& str)",<<
"This method has not been implemented");
107 for(map<
string,pair<size_t,char*> >::const_iterator it=
registry.begin() ; it!=
registry.end() ; ++it)
109 oss<<
"Key = "<< it->first <<
" , size : "<<it->second.first<<
" ASCII value : "<<string((
char*) it->second.second,it->second.first)<<endl ;
123 for(
size_t i=0;i<nKeys;++i)
128 value =
new char[
size] ;
129 buffer.
get(value,size) ;
132 map<string,pair<size_t,char*> >::iterator it=
registry.find(key) ;
135 delete[] it->second.second ;
138 registry.insert(pair<
string, pair<size_t,char*> >(key, pair<size_t,char*>(size,value))) ;
149 ofstream file(filename.c_str(), ofstream::out ) ;
151 file.write((
const char*) &size,
sizeof(size)) ;
152 file.write((
const char*) buffer.
start(),
size) ;
158 ifstream file(filename.c_str(), ifstream::in | ifstream::binary) ;
161 file.read((
char*) &size,
sizeof(size)) ;
164 file.read((
char*) buffer.
ptr(),
size) ;
175 for(map<
string,pair<size_t,char*> >::const_iterator it=inRegistry.
registry.begin() ; it!=inRegistry.
registry.end() ; ++it)
177 const string& key=it->first ;
178 map<string,pair<size_t,char*> >::iterator it2=
registry.find(key) ;
181 size=it->second.first ;
182 value=
new char[
size] ;
183 memcpy(value,it->second.second,size) ;
184 registry.insert(pair<
string, pair<size_t,char*> >(key, pair<size_t,char*>(size,value))) ;
219 MPI_Comm_rank(comm,&rank);
220 MPI_Comm_size(comm,&mpiSize);
222 int* sizes=
new int[mpiSize] ;
225 int localSize=localBuffer.
count() ;
226 MPI_Gather(&localSize,1,MPI_INT,sizes,1,MPI_INT,0,comm) ;
233 size_t globalBufferSize=0 ;
234 displs=
new int[mpiSize] ;
235 for (
int i=0;i<mpiSize;++i)
237 displs[i]=globalBufferSize ;
238 globalBufferSize+=sizes[i] ;
241 globalBuffer=
new char[globalBufferSize] ;
242 MPI_Gatherv(localBuffer.
start(),localSize,MPI_CHAR,globalBuffer,sizes,displs,MPI_CHAR,0,comm) ;
243 for(
int i=1;i<mpiSize;++i)
245 CBufferIn buffer(globalBuffer+displs[i],sizes[i]) ;
251 delete[] globalBuffer ;
253 else MPI_Gatherv(localBuffer.
start(),localSize,MPI_CHAR,globalBuffer,sizes,displs,MPI_CHAR,0,comm) ;
265 int mpiRank,mpiSize ;
266 MPI_Comm_rank(comm,&mpiRank);
267 MPI_Comm_size(comm,&mpiSize);
272 if (mpiRank<mpiSize/2+mpiSize%2) color=0 ;
275 MPI_Comm_split(comm,color,mpiRank,&commUp) ,
277 MPI_Comm_free(&commUp) ;
285 if (mpiRank==0 || mpiRank==mpiSize/2+mpiSize%2) color=0 ;
287 MPI_Comm_split(comm,color,mpiRank,&commDown) ;
289 MPI_Comm_free(&commDown) ;
virtual bool toBuffer(CBufferOut &buffer) const =0
bool toBuffer(CBufferOut &buffer) const
virtual bool isEmpty(void) const =0
void gatherRegistry(void)
virtual size_t size(void) const =0
void fromFile(const string &filename)
virtual bool fromBuffer(CBufferIn &buffer)=0
string toString(void) const
void mergeRegistry(const CRegistry &inRegistry)
void getKey_(const std::string &key, CBaseType &value)
void toFile(const string &filename)
std::map< std::string, std::pair< size_t, char * > > registry
This class is a registry database which store key with an associated value.
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())
void setKey_(const std::string &key, const CBaseType &value)
CRegistry(const MPI_Comm &comm=MPI_COMM_WORLD)
void fromString(const string &str)
bool foundKey(const std::string &key) const
bool fromBuffer(CBufferIn &buffer)
void hierarchicalGatherRegistry(void)
virtual void reset(void)=0