Import Geant4 10.3.0 source tree
This commit is contained in:
@@ -13,10 +13,17 @@ extern "C" {
|
||||
typedef void* MPI_Comm;
|
||||
typedef void* MPI_Datatype;
|
||||
|
||||
#define MPI_UNSIGNED 0
|
||||
#define MPI_DOUBLE 0
|
||||
#define MPI_UNSIGNED_CHAR 0
|
||||
#define MPI_CHAR 0
|
||||
#define MPI_UNSIGNED 0
|
||||
#define MPI_DOUBLE 0
|
||||
#define MPI_UNSIGNED_CHAR 0
|
||||
#define MPI_CHAR 0
|
||||
#define MPI_LONG 0
|
||||
#define MPI_INT 0
|
||||
#define MPI_UNSIGNED_LONG 0
|
||||
#define MPI_LONG_LONG 0
|
||||
#define MPI_UNSIGNED_LONG_LONG 0
|
||||
|
||||
#define MPI_ANY_SOURCE 0
|
||||
|
||||
#define MPI_SUCCESS 1
|
||||
|
||||
@@ -32,7 +39,11 @@ inline int MPI_Unpack(const void*,int,int*,void*,int,MPI_Datatype,MPI_Comm){retu
|
||||
/// to pass h2mpi, hs2mpi /////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
typedef int MPI_Status;
|
||||
struct _MPI_Status {
|
||||
int MPI_SOURCE;
|
||||
int MPI_TAG;
|
||||
};
|
||||
typedef _MPI_Status MPI_Status;
|
||||
|
||||
inline int MPI_Probe(int,int,MPI_Comm,MPI_Status*){return 0;}
|
||||
inline int MPI_Get_count(const MPI_Status*,MPI_Datatype,int*){return 0;}
|
||||
|
||||
@@ -264,5 +264,3 @@ protected:
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
//exlib_build_use inlib mpi
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_mpi_pntuple
|
||||
#define tools_mpi_pntuple
|
||||
|
||||
// pntuple = for parallel ntupling.
|
||||
|
||||
#include <tools/wroot/base_pntuple>
|
||||
#include <tools/S_STRING>
|
||||
#include <tools/impi>
|
||||
|
||||
namespace tools {
|
||||
namespace mpi {
|
||||
|
||||
class pntuple : public tools::wroot::base_pntuple {
|
||||
typedef tools::wroot::base_pntuple parent;
|
||||
public:
|
||||
static tools::uint32 protocol_basket() {return 1;}
|
||||
static tools::uint32 protocol_end_fill() {return 2;}
|
||||
public:
|
||||
pntuple(std::ostream& a_out,
|
||||
bool a_byte_swap,tools::uint32 a_compression,
|
||||
const std::string& a_name,const std::string& a_title,bool a_verbose)
|
||||
:parent(a_out,a_byte_swap,a_compression,a_name,a_title,a_verbose)
|
||||
{}
|
||||
pntuple(std::ostream& a_out,bool a_byte_swap,tools::uint32 a_compression,tools::wroot::seek a_seek_directory,
|
||||
const std::vector<tools::uint32>& a_basket_sizes,const tools::ntuple_booking& a_bkg,bool a_verbose)
|
||||
:parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_basket_sizes,a_bkg,a_verbose)
|
||||
{}
|
||||
virtual ~pntuple() {}
|
||||
protected:
|
||||
pntuple(const pntuple& a_from):parent(a_from){}
|
||||
pntuple& operator=(const pntuple& a_from){parent::operator=(a_from);return *this;}
|
||||
|
||||
protected:
|
||||
class basket_add : public virtual tools::wroot::branch::iadd_basket {
|
||||
typedef tools::wroot::branch::iadd_basket parent;
|
||||
public:
|
||||
virtual bool add_basket(tools::wroot::basket& a_basket) {
|
||||
m_mpi.pack_reset();
|
||||
if(!m_mpi.pack(protocol_basket())) return false;
|
||||
if(!m_mpi.pack(m_icol)) return false;
|
||||
|
||||
if(!m_mpi.spack(a_basket.object_name())) return false;
|
||||
if(!m_mpi.spack(a_basket.object_title())) return false;
|
||||
|
||||
if(!m_mpi.pack(a_basket.last())) return false;
|
||||
if(!m_mpi.pack(a_basket.nev_buf_size())) return false;
|
||||
if(!m_mpi.pack(a_basket.nev())) return false;
|
||||
|
||||
if(a_basket.entry_offset()) {
|
||||
if(!m_mpi.bpack(true)) return false;
|
||||
if(!m_mpi.pack(a_basket.nev_buf_size(),a_basket.entry_offset())) return false;
|
||||
} else {
|
||||
if(!m_mpi.bpack(false)) return false;
|
||||
}
|
||||
|
||||
if(a_basket.displacement()) {
|
||||
if(!m_mpi.bpack(true)) return false;
|
||||
if(!m_mpi.pack(a_basket.nev_buf_size(),a_basket.displacement())) return false;
|
||||
} else {
|
||||
if(!m_mpi.bpack(false)) return false;
|
||||
}
|
||||
|
||||
if(!m_mpi.pack(a_basket.datbuf().length(),a_basket.datbuf().buf())) return false;
|
||||
|
||||
if(!m_mpi.send_buffer(m_dest,m_tag)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
basket_add(file& a_file,tools::impi& a_mpi,int a_dest,int a_tag,tools::uint32 a_icol)
|
||||
:m_file(a_file),m_mpi(a_mpi),m_dest(a_dest),m_tag(a_tag),m_icol(a_icol)
|
||||
{}
|
||||
protected:
|
||||
basket_add(const basket_add& a_from):parent()
|
||||
,m_file(a_from.m_file),m_mpi(a_from.m_mpi),m_dest(a_from.m_dest),m_tag(a_from.m_tag),m_icol(a_from.m_icol)
|
||||
{}
|
||||
basket_add& operator=(const basket_add& a_from){
|
||||
m_file = a_from.m_file;
|
||||
m_dest = a_from.m_dest;
|
||||
m_tag = a_from.m_tag;
|
||||
m_icol = a_from.m_icol;
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
file m_file;
|
||||
tools::impi& m_mpi;
|
||||
int m_dest;
|
||||
int m_tag;
|
||||
tools::uint32 m_icol;
|
||||
};
|
||||
|
||||
public:
|
||||
bool add_row(tools::impi& a_mpi,int a_dest,int a_tag) {
|
||||
if(m_cols.empty()) return false;
|
||||
|
||||
tools_vforit(tools::wroot::icol*,m_cols,it) (*it)->add();
|
||||
|
||||
tools::uint32 icol = 0;
|
||||
tools_vforit(tools::wroot::icol*,m_cols,it) {
|
||||
basket_add _badd(m_file,a_mpi,a_dest,a_tag,icol);icol++;
|
||||
if(!(*it)->get_branch()->pfill(_badd)) return false;
|
||||
}
|
||||
|
||||
tools_vforit(tools::wroot::icol*,m_cols,it) (*it)->set_def();
|
||||
return true;
|
||||
}
|
||||
protected:
|
||||
void end_leaves(std::vector<tools::uint32>& a_lengths,std::vector<int>& a_mxs) const {
|
||||
a_lengths.clear();
|
||||
a_mxs.clear();
|
||||
tools_vforcit(tools::wroot::icol*,m_cols,it) {
|
||||
tools::wroot::base_leaf* _leaf = (*it)->get_leaf();
|
||||
tools::wroot::leaf_string* _leafs = _leaf?tools::id_cast<tools::wroot::base_leaf,tools::wroot::leaf_string>(*_leaf):0;
|
||||
if(_leafs) {
|
||||
a_lengths.push_back(_leafs->length());
|
||||
a_mxs.push_back(_leafs->get_max());
|
||||
}
|
||||
}
|
||||
}
|
||||
public:
|
||||
bool end_fill(tools::impi& a_mpi,int a_dest,int a_tag) {
|
||||
tools::uint32 icol = 0;
|
||||
tools_vforit(tools::wroot::icol*,m_cols,it) {
|
||||
basket_add _badd(m_file,a_mpi,a_dest,a_tag,icol);icol++;
|
||||
if(!(*it)->get_branch()->end_pfill(_badd)) return false;
|
||||
}
|
||||
std::vector<tools::uint32> lengths;
|
||||
std::vector<int> mxs;
|
||||
end_leaves(lengths,mxs);
|
||||
|
||||
a_mpi.pack_reset();
|
||||
if(!a_mpi.pack(protocol_end_fill())) return false;
|
||||
if(!a_mpi.vpack(lengths)) return false;
|
||||
if(!a_mpi.vpack(mxs)) return false;
|
||||
if(!a_mpi.send_buffer(a_dest,a_tag)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
inline tools::wroot::basket* get_basket(std::ostream& a_out,tools::impi& a_mpi,
|
||||
bool a_byte_swap,tools::wroot::seek a_seek_directory,
|
||||
tools::uint32 a_basket_size) {
|
||||
std::string oname;
|
||||
if(!a_mpi.sunpack(oname)) return 0;
|
||||
std::string otitle;
|
||||
if(!a_mpi.sunpack(otitle)) return 0;
|
||||
|
||||
tools::uint32 last,nev_buf_size,nev;
|
||||
if(!a_mpi.unpack(last)) return 0;
|
||||
if(!a_mpi.unpack(nev_buf_size)) return 0;
|
||||
if(!a_mpi.unpack(nev)) return 0;
|
||||
|
||||
int* entry_offset = 0;
|
||||
{bool not_null;
|
||||
if(!a_mpi.bunpack(not_null)) return 0;
|
||||
if(not_null) {
|
||||
tools::uint32 n;
|
||||
if(!a_mpi.unpack(n,entry_offset)) return 0;
|
||||
}}
|
||||
|
||||
int* displacement = 0;
|
||||
{bool not_null;
|
||||
if(!a_mpi.bunpack(not_null)) return 0;
|
||||
if(not_null) {
|
||||
tools::uint32 n;
|
||||
if(!a_mpi.unpack(n,displacement)) return 0;
|
||||
}}
|
||||
|
||||
tools::uint32 _size;
|
||||
char* _buffer;
|
||||
if(!a_mpi.unpack(_size,_buffer)) {a_out << "unpack(buffer) failed."<< std::endl;return 0;}
|
||||
|
||||
// wbasket fields set at file writing :
|
||||
//m_buf_size,m_buffer,m_nbytes,m_object_size,m_date,m_cycle,m_seek_key
|
||||
|
||||
//::printf("debug : col = %d, %s, %s, %lu\n",
|
||||
// icol,rbasket.object_class().c_str(),rbasket.object_name().c_str(),rbasket.seek_key());
|
||||
|
||||
tools::wroot::basket* basket = new tools::wroot::basket(a_out,a_byte_swap,a_seek_directory,
|
||||
oname,otitle,"TBasket",a_basket_size,
|
||||
false/*verbose*/);
|
||||
basket->datbuf().write_fast_array(_buffer,_size);
|
||||
basket->set_nev(last,nev_buf_size,nev,entry_offset,displacement);
|
||||
|
||||
delete [] _buffer;
|
||||
|
||||
return basket;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,70 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_mpi_wait_buffer
|
||||
#define tools_mpi_wait_buffer
|
||||
|
||||
#ifdef TOOLS_USE_NATIVE_MPI
|
||||
#include <mpi.h>
|
||||
#else
|
||||
#include "dummy_mpi.h"
|
||||
#endif
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace tools {
|
||||
namespace mpi {
|
||||
|
||||
inline bool wait_buffer(std::ostream& a_out,int a_rank,int a_src,int a_tag,const MPI_Comm& a_comm,
|
||||
int& a_buffer_size,char*& a_buffer,int& a_probe_src,bool a_verbose = false) {
|
||||
a_buffer = 0;
|
||||
a_buffer_size = 0;
|
||||
a_probe_src = -1;
|
||||
|
||||
MPI_Status status;
|
||||
if(::MPI_Probe(a_src,a_tag,a_comm,&status)!=MPI_SUCCESS) {
|
||||
a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : MPI_Probe : failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(::MPI_Get_count(&status,MPI_CHAR,&a_buffer_size)!=MPI_SUCCESS) {
|
||||
a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : MPI_Get_count : failed." << std::endl;
|
||||
a_buffer_size = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
a_probe_src = status.MPI_SOURCE;
|
||||
|
||||
if(!a_buffer_size) {
|
||||
a_out << "exlb::mpi::wait_buffer : MPI_Get_count returns zero data." << std::endl;
|
||||
a_probe_src = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(a_verbose) a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : get_count " << a_buffer_size << std::endl;
|
||||
|
||||
a_buffer = new char[a_buffer_size];
|
||||
if(!a_buffer) {
|
||||
a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : can't alloc buffer of size " << a_buffer_size << std::endl;
|
||||
a_buffer_size = 0;
|
||||
a_probe_src = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(::MPI_Recv(a_buffer,a_buffer_size,MPI_CHAR,status.MPI_SOURCE,status.MPI_TAG,a_comm,&status)!=MPI_SUCCESS) {
|
||||
a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : MPI_Recv : failed." << std::endl;
|
||||
a_buffer_size = 0;
|
||||
delete [] a_buffer;
|
||||
a_buffer = 0;
|
||||
a_probe_src = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(a_verbose) a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : unpack data ..." << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -72,6 +72,4 @@ protected:
|
||||
|
||||
}}
|
||||
|
||||
//exlib_build_use inlib mpi
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include <tools/impi>
|
||||
#include <tools/vdata>
|
||||
#include <tools/typedefs>
|
||||
#include <tools/realloc>
|
||||
#include <tools/mnmx>
|
||||
#include <ostream>
|
||||
@@ -21,13 +20,34 @@
|
||||
#include <tools/mem>
|
||||
#endif
|
||||
|
||||
// the below must be in sync with inlib/typedefs
|
||||
#ifdef _MSC_VER
|
||||
//typedef __int64 int64;
|
||||
//typedef unsigned __int64 uint64;
|
||||
#define TOOLS_MPI_UINT64 MPI_UNSIGNED_LONG_LONG
|
||||
#define TOOLS_MPI_INT64 MPI_LONG_LONG
|
||||
#elif defined(_LP64)
|
||||
// 64 Bit Platforms
|
||||
//typedef long int64;
|
||||
//typedef unsigned long uint64;
|
||||
#define TOOLS_MPI_UINT64 MPI_UNSIGNED_LONG
|
||||
#define TOOLS_MPI_INT64 MPI_LONG
|
||||
#else
|
||||
// 32-Bit Platforms
|
||||
//typedef long long int64;
|
||||
//typedef unsigned long long uint64;
|
||||
#define TOOLS_MPI_UINT64 MPI_UNSIGNED_LONG_LONG
|
||||
#define TOOLS_MPI_INT64 MPI_LONG_LONG
|
||||
#endif
|
||||
|
||||
namespace tools {
|
||||
namespace mpi {
|
||||
|
||||
class wrmpi : public virtual tools::impi {
|
||||
typedef tools::impi parent;
|
||||
protected:
|
||||
public:
|
||||
typedef unsigned int num_t;
|
||||
protected:
|
||||
static const std::string& s_class() {
|
||||
static const std::string s_v("tools::mpi::wrmpi");
|
||||
return s_v;
|
||||
@@ -43,6 +63,26 @@ public: //inlib::mpi::impi
|
||||
m_pos += sz;
|
||||
return true;
|
||||
}
|
||||
virtual bool pack(tools::uint64 a_val) {
|
||||
tools::uint32 sz = tools::uint32(sizeof(tools::uint64));
|
||||
if(m_pos+sz>m_max) {if(!expand2(m_size+sz)) return false;}
|
||||
if(::MPI_Pack(&a_val,1,TOOLS_MPI_UINT64,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
|
||||
m_out << "tools::mpi::wrmpi : MPI_Pack(uint64) failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
m_pos += sz;
|
||||
return true;
|
||||
}
|
||||
virtual bool pack(tools::int64 a_val) {
|
||||
tools::uint32 sz = tools::uint32(sizeof(tools::int64));
|
||||
if(m_pos+sz>m_max) {if(!expand2(m_size+sz)) return false;}
|
||||
if(::MPI_Pack(&a_val,1,TOOLS_MPI_INT64,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
|
||||
m_out << "tools::mpi::wrmpi : MPI_Pack(int64) failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
m_pos += sz;
|
||||
return true;
|
||||
}
|
||||
virtual bool pack(double a_val) {
|
||||
tools::uint32 sz = tools::uint32(sizeof(double));
|
||||
if(m_pos+sz>m_max) {if(!expand2(m_size+sz)) return false;}
|
||||
@@ -95,13 +135,27 @@ public: //inlib::mpi::impi
|
||||
m_pos += sz;
|
||||
return true;
|
||||
}
|
||||
virtual bool vpack(const std::vector<int>& a_v) {
|
||||
if(!pack((num_t)a_v.size())) return false;
|
||||
tools::uint32 sz = (tools::uint32)(a_v.size()*sizeof(int));
|
||||
if((m_pos+sz)>m_max) {if(!expand2(m_size+sz)) return false;}
|
||||
#ifdef TOOLS_USE_MPI_PACK_NOT_CONST
|
||||
if(::MPI_Pack(const_cast<int*>(tools::vec_data(a_v)),a_v.size(),MPI_INT,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
|
||||
#else
|
||||
if(::MPI_Pack(tools::vec_data(a_v),a_v.size(),MPI_INT,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
|
||||
#endif
|
||||
m_out << "tools::mpi::wrmpi : MPI_Pack(std::vector<int>) failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
m_pos += sz;
|
||||
return true;
|
||||
}
|
||||
virtual bool vpack(const std::vector<double>& a_v) {
|
||||
if(!pack((num_t)a_v.size())) return false;
|
||||
tools::uint32 sz = (tools::uint32)(a_v.size()*sizeof(double));
|
||||
if((m_pos+sz)>m_max) {if(!expand2(m_size+sz)) return false;}
|
||||
#ifdef TOOLS_USE_MPI_PACK_NOT_CONST
|
||||
if(::MPI_Pack(const_cast<double*>(tools::vec_data(a_v)),a_v.size(),
|
||||
MPI_DOUBLE,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
|
||||
if(::MPI_Pack(const_cast<double*>(tools::vec_data(a_v)),a_v.size(),MPI_DOUBLE,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
|
||||
#else
|
||||
if(::MPI_Pack(tools::vec_data(a_v),a_v.size(),MPI_DOUBLE,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
|
||||
#endif
|
||||
@@ -111,6 +165,37 @@ public: //inlib::mpi::impi
|
||||
m_pos += sz;
|
||||
return true;
|
||||
}
|
||||
virtual bool pack(tools::uint32 a_size,const char* a_buffer) {
|
||||
if(!pack((num_t)a_size)) return false;
|
||||
tools::uint32 sz = (tools::uint32)(a_size*sizeof(char));
|
||||
if((m_pos+sz)>m_max) {if(!expand2(m_size+sz)) return false;}
|
||||
#ifdef TOOLS_USE_MPI_PACK_NOT_CONST
|
||||
if(::MPI_Pack(const_cast<char*>(a_buffer),a_size,MPI_CHAR,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
|
||||
#else
|
||||
if(::MPI_Pack(a_buffer,a_size,MPI_CHAR,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
|
||||
#endif
|
||||
m_out << "tools::mpi::wrmpi : MPI_Pack(char*) failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
m_pos += sz;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool pack(tools::uint32 a_size,const int* a_buffer) {
|
||||
if(!pack((num_t)a_size)) return false;
|
||||
tools::uint32 sz = (tools::uint32)(a_size*sizeof(int));
|
||||
if((m_pos+sz)>m_max) {if(!expand2(m_size+sz)) return false;}
|
||||
#ifdef TOOLS_USE_MPI_PACK_NOT_CONST
|
||||
if(::MPI_Pack(const_cast<int*>(a_buffer),a_size,MPI_INT,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
|
||||
#else
|
||||
if(::MPI_Pack(a_buffer,a_size,MPI_INT,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
|
||||
#endif
|
||||
m_out << "tools::mpi::wrmpi : MPI_Pack(int*) failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
m_pos += sz;
|
||||
return true;
|
||||
}
|
||||
public: //inlib::mpi::impi
|
||||
virtual bool unpack(unsigned int& a_val) {
|
||||
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,&a_val,1,MPI_UNSIGNED,m_comm)!=MPI_SUCCESS) {
|
||||
@@ -120,6 +205,22 @@ public: //inlib::mpi::impi
|
||||
}
|
||||
return true;
|
||||
}
|
||||
virtual bool unpack(tools::uint64& a_val) {
|
||||
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,&a_val,1,TOOLS_MPI_UINT64,m_comm)!=MPI_SUCCESS) {
|
||||
m_out << "tools::mpi::wrmpi : MPI_Unpack(uint64) failed." << std::endl;
|
||||
a_val = 0;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
virtual bool unpack(tools::int64& a_val) {
|
||||
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,&a_val,1,TOOLS_MPI_INT64,m_comm)!=MPI_SUCCESS) {
|
||||
m_out << "tools::mpi::wrmpi : MPI_Unpack(int64) failed." << std::endl;
|
||||
a_val = 0;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
virtual bool unpack(double& a_val) {
|
||||
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,&a_val,1,MPI_DOUBLE,m_comm)!=MPI_SUCCESS) {
|
||||
m_out << "tools::mpi::wrmpi : MPI_Unpack(double) failed." << std::endl;
|
||||
@@ -150,6 +251,17 @@ public: //inlib::mpi::impi
|
||||
}
|
||||
return true;
|
||||
}
|
||||
virtual bool vunpack(std::vector<int>& a_v) {
|
||||
num_t num;
|
||||
if(!unpack(num)) {a_v.clear();return false;}
|
||||
a_v.resize(num);
|
||||
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,tools::vec_data(a_v),a_v.size(),MPI_INT,m_comm)!=MPI_SUCCESS) {
|
||||
m_out << "tools::mpi::wrmpi : MPI_Unpack(std::vector<int>) failed." << std::endl;
|
||||
a_v.clear();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
virtual bool vunpack(std::vector<double>& a_v) {
|
||||
num_t num;
|
||||
if(!unpack(num)) {a_v.clear();return false;}
|
||||
@@ -172,7 +284,52 @@ public: //inlib::mpi::impi
|
||||
}
|
||||
return true;
|
||||
}
|
||||
virtual bool unpack(tools::uint32& a_size,char*& a_buffer) {
|
||||
num_t num;
|
||||
if(!unpack(num)) {a_size = 0;a_buffer = 0;return false;}
|
||||
a_buffer = new char[num];
|
||||
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,a_buffer,num,MPI_CHAR,m_comm)!=MPI_SUCCESS) {
|
||||
m_out << "tools::mpi::wrmpi : MPI_Unpack(char*) failed." << std::endl;
|
||||
delete [] a_buffer;
|
||||
a_size = 0;
|
||||
a_buffer = 0;
|
||||
return false;
|
||||
}
|
||||
a_size = num;
|
||||
return true;
|
||||
}
|
||||
virtual bool unpack(tools::uint32& a_size,int*& a_buffer) {
|
||||
num_t num;
|
||||
if(!unpack(num)) {a_size = 0;a_buffer = 0;return false;}
|
||||
a_buffer = new int[num];
|
||||
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,a_buffer,num,MPI_INT,m_comm)!=MPI_SUCCESS) {
|
||||
m_out << "tools::mpi::wrmpi : MPI_Unpack(int*) failed." << std::endl;
|
||||
delete [] a_buffer;
|
||||
a_size = 0;
|
||||
a_buffer = 0;
|
||||
return false;
|
||||
}
|
||||
a_size = num;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void pack_reset() {
|
||||
delete [] m_buffer;
|
||||
m_size = 128;
|
||||
m_buffer = new char[m_size];
|
||||
//if(!m_buffer) {}
|
||||
m_max = m_buffer+m_size;
|
||||
m_pos = m_buffer;
|
||||
m_ipos = 0; //IMPORTANT
|
||||
}
|
||||
|
||||
virtual bool send_buffer(int a_dest,int a_tag) { // used in tools/mpi/pntuple.
|
||||
if(::MPI_Send(m_buffer,m_ipos,MPI_CHAR,a_dest,a_tag,m_comm)!=MPI_SUCCESS) {
|
||||
m_out << "tools::mpi::wrmpi::send_buffer : MPI_Send() failed for rank destination " << a_dest << "." << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
wrmpi(std::ostream& a_out,const MPI_Comm& a_comm,tools::uint32 a_size = 128) // we expect a_size!=0
|
||||
:m_out(a_out)
|
||||
@@ -236,15 +393,7 @@ public:
|
||||
#else
|
||||
const char* buffer() const {return m_buffer;}
|
||||
#endif
|
||||
void pack_reset() {
|
||||
delete [] m_buffer;
|
||||
m_size = 128;
|
||||
m_buffer = new char[m_size];
|
||||
//if(!m_buffer) {}
|
||||
m_max = m_buffer+m_size;
|
||||
m_pos = m_buffer;
|
||||
m_ipos = 0; //IMPORTANT
|
||||
}
|
||||
|
||||
protected:
|
||||
bool expand2(tools::uint32 a_new_size) {return expand(tools::mx<tools::uint32>(2*m_size,a_new_size));} //CERN-ROOT logic.
|
||||
|
||||
@@ -280,6 +429,3 @@ protected:
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//exlib_build_use inlib mpi
|
||||
|
||||
Reference in New Issue
Block a user