48 int data_size=data.size();
51 typename T::value_type *buffer=
new typename T::value_type[data_size];
55 for(
typename T::const_iterator
iter=data.begin();
58 void* buf=
reinterpret_cast<void*
>(&(buffer[count]));
59 new(buf)(
typename T::value_type)(*iter);
88 int nb_data=data.size();
92 for(
typename T::const_iterator
iter=data.begin();
112 template <
typename T>
125 template <
typename T>
138 template <
typename T>
146 typename T::value_type *buffer=
new typename T::value_type[data_size];
151 for(
int i=0;i<data_size;i++){
152 data.insert(data.end(),buffer[i]);
165 template <
typename T>
183 for(
int i=0;i<nb_data;i++){
184 typename T::value_type tv;
186 data.insert(data.end(),tv);
200 template <
typename T>
204 int total_size=data.size();
205 T* buffer=
new T[total_size];
206 int comm_size=
size();
207 int *size_buffer=
new int[comm_size];
208 int *offs_buffer=
new int[comm_size];
211 for(
int i=0;i<comm_size;i++){
212 typename multimap<int,T>::const_iterator begin=data.find(i);
213 typename multimap<int,T>::const_iterator end=data.upper_bound(i);
214 if(begin!=data.end()){
215 for(
typename multimap<int,T>::const_iterator
iter=begin;
218 buffer[count]=
iter->second;
222 size_buffer[i]=count-count_p;
227 MPI_Scatter(size_buffer,1,MPI_INT,&dummy,1,MPI_INT,
rank(),
m_comm);
230 for(
int i=1;i<comm_size;i++){
231 offs_buffer[i]=offs_buffer[i-1]+size_buffer[i-1];
237 delete [] size_buffer;
238 delete [] offs_buffer;
248 template <
typename T>
253 MPI_Scatter(
NULL,0,MPI_INT,&size,1,MPI_INT,root,
m_comm);
255 typename T::value_type *buffer=
new typename T::value_type[
size];
259 for(
int i=0;i<
size;i++){
260 data.insert(data.end(),buffer[i]);
272 template <
typename T>
276 int comm_size=
size();
277 int *size_buffer=
new int[comm_size];
278 int *offs_buffer=
new int[comm_size];
280 MPI_Gather(&dummy,1,MPI_INT,size_buffer,1,MPI_INT,
rank(),
m_comm);
282 for(
int i=0;i<comm_size;i++){
283 totalsize+=size_buffer[i];
286 T *buffer=
new T[totalsize];
289 for(
int i=1;i<comm_size;i++){
290 offs_buffer[i]=offs_buffer[i-1]+size_buffer[i-1];
296 for(
int i=0;i<comm_size;i++){
297 for(
int j=offs_buffer[i];j<offs_buffer[i]+size_buffer[i];j++){
298 data.insert(pair<int,T>(i,buffer[j]));
302 delete [] size_buffer;
303 delete [] offs_buffer;
314 template <
typename T>
318 int comm_size=
size();
319 int *size_buffer=
new int[comm_size];
320 int *offs_buffer=
new int[comm_size];
322 MPI_Gather(&dummy,1,MPI_INT,size_buffer,1,MPI_INT,
rank(),
m_comm);
324 for(
int i=0;i<comm_size;i++){
325 console.
Debug() <<
"buffer size " << i <<
" - " << size_buffer[i] <<
"\n";
326 totalsize+=size_buffer[i];
329 T *buffer=
new T[totalsize];
332 for(
int i=1;i<comm_size;i++){
333 offs_buffer[i]=offs_buffer[i-1]+size_buffer[i-1];
339 for(
int i=0;i<comm_size;i++){
340 for(
int j=offs_buffer[i];j<offs_buffer[i]+size_buffer[i];j++){
341 data.insert(pair<int,T>(i,buffer[j]));
345 delete [] size_buffer;
346 delete [] offs_buffer;
356 template <
typename T>
360 int size=data.size();
361 MPI_Gather(&size,1,MPI_INT,
NULL,0,MPI_INT,root,
m_comm);
363 typename T::value_type *buffer=
new typename T::value_type[
size];
366 for(
typename T::const_iterator
iter=data.begin();
385 template <
typename T>
389 int size=data.size();
391 MPI_Gather(&size,1,MPI_INT,
NULL,0,MPI_INT,root,
m_comm);
393 typename T::value_type *buffer=
new typename T::value_type[
size];
396 for(
typename T::const_iterator
iter=data.begin();
417 template <
typename T>
420 int comm_size=
size();
424 for(
int i=1;i<comm_size;i++){
425 typename multimap<int,T>::const_iterator begin=data.find(i);
426 typename multimap<int,T>::const_iterator end=data.upper_bound(i);
427 (*msg)[i].pack(
int(data.count(i)));
428 if(begin!=data.end()){
429 for(
typename multimap<int,T>::const_iterator
iter=begin;
432 (*msg)[i].pack(
iter->second);
454 template <
typename T>
459 MPI_Scatter(
NULL,0,MPI_INT,&msg_size,1,MPI_INT,root,
m_comm);
470 typename T::value_type item;
471 for(
int i=0;i<nitems;i++){
473 data.insert(data.end(),item);
479 template <
typename T>
484 int comm_size=
size();
485 int *size_buffer=
new int[comm_size];
486 int *offs_buffer=
new int[comm_size];
489 <<
"TML_Comm::gather_packed: gathering sizes\n";
490 MPI_Gather(&dummy,1,MPI_INT,size_buffer,1,MPI_INT,
rank(),
m_comm);
492 for(
int i=0;i<comm_size;i++){
496 totalsize+=size_buffer[i];
499 <<
"TML_Comm::gather_packed: total msg size = " << totalsize <<
"\n";
506 for(
int i=1;i<comm_size;i++){
507 offs_buffer[i]=offs_buffer[i-1]+size_buffer[i-1];
512 <<
"TML_Comm::gather_packed: gathering data\n";
514 &dummy2,0,
GetType(dummy), msg->
buffer(), size_buffer, offs_buffer,
519 <<
"TML_Comm::gather_packed: unpacking into multi-map\n";
520 for(
int i=0;i<comm_size;i++){
521 if (size_buffer[i] > 0)
523 const int numElems = msg->
pop_int();
524 for(
int j=0; j < numElems; j++){
530 data.insert(pair<int,T>(i, t));
534 console.
Debug() <<
"TML_Comm::gather_packed: done unpacking into multi-map\n";
536 delete [] size_buffer;
537 delete [] offs_buffer;
542 template <
typename T>
545 console.
Debug() <<
"TML_Comm::send_gather_packed: enter\n";
550 std::max(static_cast<size_t>(64), data.size()*
sizeof(
typename T::value_type))
553 const int numElems = data.
size();
555 for(
typename T::const_iterator
iter=data.begin();
563 console.
Debug() <<
"TML_Comm::send_gather_packed: sending data size...\n";
564 MPI_Gather(&size,1,MPI_INT,
NULL,0,MPI_INT,root,
m_comm);
567 console.
Debug() <<
"TML_Comm::send_gather_packed: sending data...\n";
575 console.
Debug() <<
"TML_Comm::send_gather_packed: exit\n";
578 template <
typename T>
583 MPI_Datatype data_type=
GetType(data);
584 MPI_Allreduce((
void*)(&data),(
void*)(&res),1,data_type,MPI_SUM,
m_comm);
void recv_scatter(T &, int)
Definition: comm_coll.hpp:249
void send_gather(T &, int)
Definition: comm_coll.hpp:357
virtual void begin_unpack()
Definition: packed_message.h:55
void broadcast_cont_packed(const T &)
Definition: comm_coll.hpp:85
virtual int pop_int()
Definition: packed_message.cpp:138
void send_gather_packed(const T &, int)
Definition: comm_coll.hpp:543
boost::python::object iter(const boost::python::object &pyOb)
Definition: Util.h:25
Message buffer for sending and receiving packed data. Data types are not checked. The implementation ...
Definition: packed_message.h:34
int size()
Definition: comm.cpp:69
char * buffer()
Definition: packed_multi_message.h:58
T sum_all(const T &)
Definition: comm_coll.hpp:579
void send_gather_debug(T &, int)
Definition: comm_coll.hpp:386
void scatter_packed(const multimap< int, T >)
Definition: comm_coll.hpp:418
static SGetType GetType
Definition: gettype.h:95
void gather_debug(multimap< int, T > &)
Definition: comm_coll.hpp:315
void recv_broadcast_array(T *, int, int)
Definition: comm_coll.hpp:126
int * offsets()
Definition: packed_multi_message.h:59
MPI_Comm m_comm
Definition: comm.h:50
int * sizes()
Definition: packed_multi_message.h:60
Message buffer for sending and receiving packed data to mutltiple receivers. Data types are not check...
Definition: packed_multi_message.h:34
#define NULL
Definition: t_list.h:17
void broadcast(T)
Definition: comm_coll.hpp:23
void recv_broadcast_cont_packed(T &, int)
Definition: comm_coll.hpp:166
void broadcast_array(T *, int)
Definition: comm_coll.hpp:35
void recv_scatter_packed(T &, int)
Definition: comm_coll.hpp:455
BasicCon & Debug(bool h=true)
set verbose level of next message to "dbg"
Definition: console.cpp:305
char * buffer()
Definition: packed_message.h:51
int size()
Definition: packed_message.h:52
void broadcast_cont(const T &)
Definition: comm_coll.hpp:46
int rank() const
Definition: comm.cpp:56
void gather(multimap< int, T > &)
Definition: comm_coll.hpp:273
void recv_broadcast(T &, int)
Definition: comm_coll.hpp:113
void scatter(const multimap< int, T >)
Definition: comm_coll.hpp:201
void gather_packed(multimap< int, T > &)
Definition: comm_coll.hpp:480
void recv_broadcast_cont(T &, int)
Definition: comm_coll.hpp:139