35 #ifndef MADNESS_WORLD_WORLDAM_H__INCLUDED 
   36 #define MADNESS_WORLD_WORLDAM_H__INCLUDED 
   90         unsigned long worldid;  
 
  102         void set_src(
ProcessID source) { src = source; }
 
  104         void set_worldid(
unsigned long id) { worldid = id; }
 
  107             MADNESS_ASSERT(handler);
 
  111         void set_size(std::size_t numbyte) { nbyte = numbyte; }
 
  113         void set_pending() { flags |= 0x1ul; }
 
  115         bool is_pending()
 const { 
return flags & 0x1ul; }
 
  117         void clear_flags() { flags = 0; }
 
  121         archive::BufferInputArchive make_input_arch()
 const {
 
  122             return archive::BufferInputArchive(
buf(),
size());
 
  125         archive::BufferOutputArchive make_output_arch()
 const {
 
  126             return archive::BufferOutputArchive(
buf(),
size());
 
  133         unsigned char* 
buf()
 const { 
return (
unsigned char*)(
this) + 
sizeof(
AmArg); }
 
  136         std::size_t 
size()
 const { 
return nbyte; }
 
  139         template <
typename T>
 
  141             return make_input_arch() & t;
 
  145         template <
typename T>
 
  147             return make_output_arch() & t;
 
  164         std::size_t narg = 1 + (nbyte+
sizeof(
AmArg)-1)/
sizeof(
AmArg);
 
  166         arg->set_size(nbyte);
 
  173         memcpy(r, &arg, arg.
size()+
sizeof(
AmArg));
 
  184     template <
typename A, 
typename B, 
typename C, 
typename D, 
typename E, 
typename F, 
typename G, 
typename H, 
typename I, 
typename J>
 
  186                              const I& i, 
const J& j) {
 
  188         *arg & a & b & c & d & e & f & g & h & i & j;
 
  193     template <
typename A, 
typename B, 
typename C, 
typename D, 
typename E, 
typename F, 
typename G, 
typename H, 
typename I>
 
  197         *arg & a & b & c & d & e & f & g & h & i;
 
  202     template <
typename A, 
typename B, 
typename C, 
typename D, 
typename E, 
typename F, 
typename G, 
typename H>
 
  205         *arg & a & b & c & d & e & f & g & h;
 
  210     template <
typename A, 
typename B, 
typename C, 
typename D, 
typename E, 
typename F, 
typename G>
 
  213         *arg & a & b & c & d & e & f & 
g;
 
  218     template <
typename A, 
typename B, 
typename C, 
typename D, 
typename E, 
typename F>
 
  221         *arg & a & b & c & d & e & 
f;
 
  226     template <
typename A, 
typename B, 
typename C, 
typename D, 
typename E>
 
  229         *arg & a & b & c & d & e;
 
  234     template <
typename A, 
typename B, 
typename C, 
typename D>
 
  237         *arg & a & b & c & d;
 
  242     template <
typename A, 
typename B, 
typename C>
 
  250     template <
typename A, 
typename B>
 
  258     template <
typename A>
 
  274         static const int DEFAULT_NSEND = 512;
 
  276         static const int DEFAULT_NSEND = 32;
 
  286         unsigned long worldid; 
 
  289         volatile int cur_msg; 
 
  290         volatile unsigned long nsent; 
 
  291         volatile unsigned long nrecv; 
 
  293         std::vector<int> map_to_comm_world; 
 
  295         void free_managed_send_buf(
int i) {
 
  297             if (managed_send_buf[i]) {
 
  299                 managed_send_buf[i] = 0;
 
  304         int get_free_send_request() {
 
  314             while (!send_req[cur_msg].Test()) {
 
  323             free_managed_send_buf(cur_msg);
 
  324             int result = cur_msg;
 
  326             if (cur_msg >= nsend) cur_msg = 0;
 
  332         static void handler(
void *buf, std::size_t nbyte) {
 
  336             AmArg* 
arg = 
static_cast<AmArg*
>(buf);
 
  338             World* w = arg->get_world();
 
  339             MADNESS_ASSERT(arg->size() + 
sizeof(AmArg) == nbyte);
 
  341             MADNESS_ASSERT(func);
 
  350                 AmArg* argx = 
const_cast<AmArg*
>(
arg);
 
  352                 argx->set_worldid(worldid);
 
  358             MADNESS_ASSERT(arg->get_world());
 
  359             MADNESS_ASSERT(arg->get_func());
 
  362             dest = map_to_comm_world[dest];
 
  366             int i = get_free_send_request();
 
  367             send_req[i] = 
RMI::isend(arg, arg->size()+
sizeof(AmArg), dest, handler, attr);
 
  368             if (managed) managed_send_buf[i] = (AmArg*)(arg);
 
  389             return isend(dest, op, arg, attr, managed);
 
  398                 for (
int i=0; i<n; ++i) {
 
  399                     free_managed_send_buf(ind[i]);
 
  413 #endif // MADNESS_WORLD_WORLDAM_H__INCLUDED 
unsigned long get_worldid() const 
Return the world id. 
Definition: worldam.h:158
void free_am_arg(AmArg *arg)
Frees an AmArg allocated with alloc_am_arg. 
Definition: worldam.h:178
World * get_world() const 
For incoming AM gives the associated world. 
Definition: worldam.h:155
Tensor< double > B
Definition: tdse1d.cc:167
Mutex using pthread mutex operations. 
Definition: worldmutex.h:94
void(* am_handlerT)(const AmArg &)
Type of AM handler functions. 
Definition: worldam.h:78
World active message that extends an RMI message. 
Definition: worldam.h:81
NDIM const Function< R, NDIM > & g
Definition: mra.h:2179
std::complex< double > func(int n, int t1, int t2, int t3, double xx, double yy, double zz)
Definition: wannier.cc:98
AmArg * alloc_am_arg(std::size_t nbyte)
Allocates a new AmArg with nbytes of user data ... delete with free_am_arg. 
Definition: worldam.h:163
size_t bufar_size(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f, const G &g, const H &h, const I &i, const J &j)
Convenience template computing the size of a buffer archive containing the arguments. 
Definition: bufar.h:105
std::size_t size() const 
Returns the size of the user's payload. 
Definition: worldam.h:136
SafeMPI::Request Request
Definition: worldrmi.h:132
virtual ~WorldAmInterface()
Definition: worldam.cc:91
const int msg_len
Max length of user payload in message. 
Definition: worldam.h:270
AmArg * new_am_arg(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f, const G &g, const H &h, const I &i, const J &j)
Convenience template for serializing arguments into a new AmArg. 
Definition: worldam.h:185
archive::BufferOutputArchive operator&(const T &t) const 
Used to serialize arguments into outgoing message. 
Definition: worldam.h:146
static Request isend(const void *buf, size_t nbyte, ProcessID dest, rmi_handlerT func, unsigned int attr=ATTR_UNORDERED)
Definition: worldrmi.h:260
Implements an archive wrapping a memory buffer. 
#define MPI_UNDEFINED
Definition: stubmpi.h:24
friend class World
Definition: worldam.h:268
NDIM & f
Definition: mra.h:2179
Tensor< typename Tensor< T >::scalar_type > arg(const Tensor< T > &t)
Return a new tensor holding the argument of each element of t (complex types only) ...
Definition: tensor.h:2429
ProcessID get_src() const 
For incoming AM gives the source process. 
Definition: worldam.h:151
WorldAmInterface(World &world)
Definition: worldam.cc:44
static World * world_from_id(unsigned long id)
Convert world id to world pointer. 
Definition: worldfwd.h:628
friend AmArg * alloc_am_arg(std::size_t nbyte)
Allocates a new AmArg with nbytes of user data ... delete with free_am_arg. 
Definition: worldam.h:163
Wraps an archive around a memory buffer for output. 
Definition: bufar.h:58
JLOOP2 NK jnz KLOOP2 mov C
Definition: mtxm_gen.h:10
Provides collectives that interoperate with the AM and task interfaces. 
Definition: worldgop.h:147
void fence()
Currently a noop. 
Definition: worldam.h:380
pcomplex_operatorT G
Definition: tdse1d.cc:168
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
archive::BufferInputArchive operator&(T &t) const 
Used to deserialize arguments from incoming message. 
Definition: worldam.h:140
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
static const attrT ATTR_ORDERED
Definition: worldrmi.h:139
RMI::Request send(const ProcessID dest, am_handlerT op, const AmArg *arg, const int attr=RMI::ATTR_ORDERED, const bool managed=true)
Sends an unmanaged non-blocking active message. 
Definition: worldam.h:386
Implements most parts of a globally addressable object (via unique ID) 
Definition: worldam.h:74
A parallel world with full functionality wrapping an MPI communicator. 
Definition: worldfwd.h:416
static const size_t HEADER_LEN
Definition: worldrmi.h:137
AmArg()
Definition: worldam.h:130
int ProcessID
Used to clearly identify process number/rank. 
Definition: worldtypes.h:37
Scoped array. 
Definition: scopedptr.h:85
Implements AM interface. 
Definition: worldam.h:266
Definition: safempi.h:243
ptrT * get() const 
Pointer accessor. 
Definition: scopedptr.h:266
Tensor< double > op(const Tensor< double > &x)
Definition: kain.cc:508
void free_managed_buffers()
Frees as many send buffers as possible. 
Definition: worldam.h:393
AmArg * copy_am_arg(const AmArg &arg)
Definition: worldam.h:171
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces. 
Definition: chem/atomutil.cc:45
const double c
Definition: gfit.cc:200
FLOAT b(int j, FLOAT z)
Definition: y1.cc:79
static int Testsome(int incount, Request *requests, int *indices, Status *statuses)
Definition: safempi.h:314
void unlock() const 
Free a mutex owned by this thread. 
Definition: worldmutex.h:124
void lock() const 
Acquire the mutex waiting if necessary. 
Definition: worldmutex.h:118
unsigned char * buf() const 
Returns a pointer to the user's payload (aligned in same way as AmArg) 
Definition: worldam.h:133