MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
message.h
1//
2// message.h
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Curtis Janssen <cljanss@limitpt.com>
7// Maintainer: LPS
8//
9// This file is part of the SC Toolkit.
10//
11// The SC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The SC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28#ifndef _util_group_message_h
29#define _util_group_message_h
30
31#include <map>
32#include <set>
33
34#include <math.h>
35#include <util/class/class.h>
36#include <util/state/state.h>
37#include <util/keyval/keyval.h>
38#include <util/group/topology.h>
39
40namespace sc {
41
42template <class T>
43class GrpReduce {
44 public:
45 GrpReduce() {}
46 virtual ~GrpReduce() {};
47 virtual void reduce(T*target, T*data, int n) = 0;
48};
49
50template <class T>
51class GrpSumReduce: public GrpReduce<T> {
52 public:
54 ~GrpSumReduce() {};
55 void reduce(T*target, T*data, int nelement);
56};
57
58template <class T>
59class GrpMinReduce: public GrpReduce<T> {
60 public:
62 ~GrpMinReduce() {};
63 void reduce(T*target, T*data, int nelement);
64};
65
66template <class T>
67class GrpMaxReduce: public GrpReduce<T> {
68 public:
70 ~GrpMaxReduce() {};
71 void reduce(T*target, T*data, int nelement);
72};
73
74template <class T, class BinaryPredicate = std::less<T> >
75class GrpCompareReduce: public GrpReduce<T> {
76 public:
79 void reduce(T*target, T*data, int nelement);
80 private:
81 BinaryPredicate Op;
82};
83
84template <class T>
86 public:
87 void reduce(T*target, T*data, int nelement);
88};
89
90template <class T>
92 public:
93 void reduce(T*target, T*data, int nelement);
94};
95
96template <class T>
98 public:
99 void reduce(T*target, T*data, int nelement);
100};
101
102template <class T>
103class GrpProductReduce: public GrpReduce<T> {
104 public:
105 void reduce(T*target, T*data, int nelement);
106};
107
108template <class T>
109class GrpFunctionReduce: public GrpReduce<T> {
110 private:
111 void (*func_)(T*target,T*data,int nelement);
112 public:
113 GrpFunctionReduce(void(*func)(T*,T*,int)):func_(func) {}
114 void reduce(T*target, T*data, int nelement);
115};
116
121 public:
123 friend class MessageGrp;
124 private:
125 int sender_;
126 int type_;
127 int nbyte_;
128 public:
129 int sender() const { return sender_; }
130 int type() const { return type_; }
131 int nbyte() const { return nbyte_; }
132 };
133 enum { AnyType = -1 };
134 enum { AnySender = -1 };
136 friend class MessageGrp;
137 private:
138 void *id_;
139 public:
140 MessageHandle(): id_(0) {}
141 MessageHandle(const MessageHandle &h): id_(h.id_) {}
142 };
143 private:
144 // These are initialized by the initialize() member (see below).
145 int me_;
146 int n_;
147 int nclass_;
148 int gop_max_;
149 std::map<ClassDescP,int> classdesc_to_index_;
150 ClassDescP *index_to_classdesc_;
151 protected:
158 void initialize(int me, int n);
159
160 Ref<MachineTopology> topology_;
161
162 int debug_;
163
164 void set_sender(MessageInfo *info,int sender) {
165 if (info) info->sender_ = sender;
166 }
167 void set_type(MessageInfo *info,int type) {
168 if (info) info->type_ = type;
169 }
170 void set_nbyte(MessageInfo *info,int nbyte) {
171 if (info) info->nbyte_ = nbyte;
172 }
173
174 void set_id(MessageHandle *handle,void *id) {
175 handle->id_ = id;
176 }
177 void *get_id(const MessageHandle *handle) {
178 return handle->id_;
179 }
180 public:
181
182 MessageGrp();
183 MessageGrp(const Ref<KeyVal>&);
184
189 virtual ~MessageGrp();
190
192 int n() { return n_; }
194 int me() { return me_; }
195
198 virtual Ref<MessageGrp> clone(void)=0;
199
209 virtual Ref<MessageGrp> split(int grpkey=0, int rankkey=0) = 0;
210
216 virtual Ref<MessageGrp> subset(const std::set<int> &) = 0;
217
223
230 static MessageGrp* initial_messagegrp(int &argc, char** &argv);
231
239 virtual void send(int target, const double* data, int ndata);
240 virtual void send(int target, const unsigned int* data, int ndata);
241 virtual void send(int target, const int* data, int ndata);
242 virtual void send(int target, const char* data, int nbyte);
243 virtual void send(int target, const unsigned char* data, int nbyte);
244 virtual void send(int target, const signed char* data, int nbyte);
245 virtual void send(int target, const short* data, int ndata);
246 virtual void send(int target, const long* data, int ndata);
247 virtual void send(int target, const float* data, int ndata);
249 void send(int target, double data) { send(target,&data,1); }
251 void send(int target, int data) { send(target,&data,1); }
252 virtual void raw_send(int target, const void* data, int nbyte) = 0;
254
263 virtual void sendt(int target, int type, const double* data, int ndata,
264 bool rcvrdy=false);
265 virtual void sendt(int target, int type, const unsigned int* data, int ndata,
266 bool rcvrdy=false);
267 virtual void sendt(int target, int type, const int* data, int ndata,
268 bool rcvrdy=false);
269 virtual void sendt(int target, int type, const char* data, int nbyte,
270 bool rcvrdy=false);
271 virtual void sendt(int target, int type, const unsigned char* data, int nbyte,
272 bool rcvrdy=false);
273 virtual void sendt(int target, int type, const signed char* data, int nbyte,
274 bool rcvrdy=false);
275 virtual void sendt(int target, int type, const short* data, int ndata,
276 bool rcvrdy=false);
277 virtual void sendt(int target, int type, const long* data, int ndata,
278 bool rcvrdy=false);
279 virtual void sendt(int target, int type, const float* data, int ndata,
280 bool rcvrdy=false);
282 void sendt(int target, int type, double data,
283 bool rcvrdy=false) {sendt(target,type,&data,1,rcvrdy);}
285 void sendt(int target, int type, int data,
286 bool rcvrdy=false) {sendt(target,type,&data,1,rcvrdy);}
287 virtual void raw_sendt(int target, int type, const void* data, int nbyte,
288 bool rcvrdy=false) = 0;
290
297 virtual void recv(int sender, double* data, int ndata);
298 virtual void recv(int sender, unsigned int* data, int ndata);
299 virtual void recv(int sender, int* data, int ndata);
300 virtual void recv(int sender, char* data, int nbyte);
301 virtual void recv(int sender, unsigned char* data, int nbyte);
302 virtual void recv(int sender, signed char* data, int nbyte);
303 virtual void recv(int sender, short* data, int ndata);
304 virtual void recv(int sender, long* data, int ndata);
305 virtual void recv(int sender, float* data, int ndata);
307 void recv(int sender, double& data) { recv(sender,&data,1); }
309 void recv(int sender, int& data) { recv(sender,&data,1); }
310 virtual void raw_recv(int sender, void* data, int nbyte,
311 MessageInfo *info=0) = 0;
313
321 virtual void recvt(int sender, int type, double* data, int ndata);
322 virtual void recvt(int sender, int type, unsigned int* data, int ndata);
323 virtual void recvt(int sender, int type, int* data, int ndata);
324 virtual void recvt(int sender, int type, char* data, int nbyte);
325 virtual void recvt(int sender, int type, unsigned char* data, int nbyte);
326 virtual void recvt(int sender, int type, signed char* data, int nbyte);
327 virtual void recvt(int sender, int type, short* data, int ndata);
328 virtual void recvt(int sender, int type, long* data, int ndata);
329 virtual void recvt(int sender, int type, float* data, int ndata);
331 void recvt(int sender, int type, double& data) {
332 recvt(sender,type,&data,1);
333 }
335 void recvt(int sender, int type, int& data) {
336 recvt(sender,type,&data,1);
337 }
338 virtual void raw_recvt(int sender, int type, void* data, int nbyte,
339 MessageInfo *info=0) = 0;
341
359 virtual void nb_sendt(int target, int type,
360 const double* data, int ndata,
361 MessageHandle&handle,
362 bool rcvrdy=false);
363 virtual void nb_sendt(int target, int type,
364 const unsigned int* data, int ndata,
365 MessageHandle&handle,
366 bool rcvrdy=false);
367 virtual void nb_sendt(int target, int type,
368 const int* data, int ndata,
369 MessageHandle&handle,
370 bool rcvrdy=false);
371 virtual void nb_sendt(int target, int type,
372 const char* data, int nbyte,
373 MessageHandle&handle,
374 bool rcvrdy=false);
375 virtual void nb_sendt(int target, int type,
376 const unsigned char* data, int nbyte,
377 MessageHandle&handle,
378 bool rcvrdy=false);
379 virtual void nb_sendt(int target, int type,
380 const signed char* data, int nbyte,
381 MessageHandle&handle,
382 bool rcvrdy=false);
383 virtual void nb_sendt(int target, int type,
384 const short* data, int ndata,
385 MessageHandle&handle,
386 bool rcvrdy=false);
387 virtual void nb_sendt(int target, int type,
388 const long* data, int ndata,
389 MessageHandle&handle,
390 bool rcvrdy=false);
391 virtual void nb_sendt(int target, int type,
392 const float* data, int ndata,
393 MessageHandle&handle,
394 bool rcvrdy=false);
395 void nb_sendt(int target, int type, double data,
396 MessageHandle&handle,
397 bool rcvrdy=false) {
398 nb_sendt(target,type,&data,1,handle,rcvrdy);
399 }
400 void nb_sendt(int target, int type, int data,
401 MessageHandle&handle,
402 bool rcvrdy=false) {
403 nb_sendt(target,type,&data,1,handle,rcvrdy);
404 }
405 virtual void raw_nb_sendt(int target, int type,
406 const void* data, int nbyte,
407 MessageHandle&,
408 bool rcvrdy=false) = 0;
410
426 virtual void nb_recvt(int sender, int type, double* data, int ndata,
427 MessageHandle&handle);
428 virtual void nb_recvt(int sender, int type, unsigned int* data, int ndata,
429 MessageHandle&handle);
430 virtual void nb_recvt(int sender, int type, int* data, int ndata,
431 MessageHandle&handle);
432 virtual void nb_recvt(int sender, int type, char* data, int nbyte,
433 MessageHandle&handle);
434 virtual void nb_recvt(int sender, int type, unsigned char* data, int nbyte,
435 MessageHandle&handle);
436 virtual void nb_recvt(int sender, int type, signed char* data, int nbyte,
437 MessageHandle&handle);
438 virtual void nb_recvt(int sender, int type, short* data, int ndata,
439 MessageHandle&handle);
440 virtual void nb_recvt(int sender, int type, long* data, int ndata,
441 MessageHandle&handle);
442 virtual void nb_recvt(int sender, int type, float* data, int ndata,
443 MessageHandle&handle);
445 void nb_recvt(int sender, int type, double& data,
446 MessageHandle&handle) {
447 nb_recvt(sender,type,&data,1,handle);
448 }
450 void nb_recvt(int sender, int type, int& data,
451 MessageHandle&handle) {
452 nb_recvt(sender,type,&data,1,handle);
453 }
454 virtual void raw_nb_recvt(int sender, int type,
455 void* data, int nbyte,
456 MessageHandle&) = 0;
458
464 virtual void wait(const MessageHandle&handle,
465 MessageInfo *info=0) = 0;
466
468 virtual int probet(int sender, int type, MessageInfo*info=0) = 0;
469
473 virtual void bcast(double* data, int ndata, int from = 0);
474 virtual void bcast(unsigned int* data, int ndata, int from = 0);
475 virtual void bcast(int* data, int ndata, int from = 0);
476 virtual void bcast(char* data, int nbyte, int from = 0);
477 virtual void bcast(unsigned char* data, int nbyte, int from = 0);
478 virtual void bcast(signed char* data, int nbyte, int from = 0);
479 virtual void bcast(short* data, int ndata, int from = 0);
480 virtual void bcast(long* data, int ndata, int from = 0);
481 virtual void bcast(float* data, int ndata, int from = 0);
482 virtual void raw_bcast(void* data, int nbyte, int from = 0);
483 void bcast(double& data, int from = 0) { bcast(&data, 1, from); }
484 void bcast(int& data, int from = 0) { bcast(&data, 1, from); }
486
491 virtual void raw_collect(const void *part, const int *lengths,
492 void *whole, int bytes_per_datum=1);
493 void collect(const double *part, const int *lengths, double *whole);
495
498 virtual void sum(double* data, int n, double* = 0, int target = -1);
499 virtual void sum(unsigned int* data, int n, unsigned int* = 0, int target = -1);
500 virtual void sum(int* data, int n, int* = 0, int target = -1);
501 virtual void sum(long* data, int n, long* = 0, int target = -1);
502 virtual void sum(unsigned long* data, int n, unsigned long* = 0, int target = -1);
503 virtual void sum(char* data, int n, char* = 0, int target = -1);
504 virtual void sum(unsigned char* data, int n,
505 unsigned char* = 0, int target = -1);
506 virtual void sum(signed char* data, int n,
507 signed char* = 0, int target = -1);
508 void sum(double& data) { sum(&data, 1); }
509 void sum(int& data) { sum(&data, 1); }
511
514 virtual void max(double* data, int n, double* = 0, int target = -1);
515 virtual void max(int* data, int n, int* = 0, int target = -1);
516 virtual void max(unsigned int* data, int n, unsigned int* = 0, int target = -1);
517 virtual void max(char* data, int n, char* = 0, int target = -1);
518 virtual void max(unsigned char* data, int n,
519 unsigned char* = 0, int target = -1);
520 virtual void max(signed char* data, int n,
521 signed char* = 0, int target = -1);
522 void max(double& data) { max(&data, 1); }
523 void max(int& data) { max(&data, 1); }
525
528 virtual void min(double* data, int n, double* = 0, int target = -1);
529 virtual void min(int* data, int n, int* = 0, int target = -1);
530 virtual void min(unsigned int* data, int n, unsigned int* = 0, int target = -1);
531 virtual void min(char* data, int n, char* = 0, int target = -1);
532 virtual void min(unsigned char* data, int n,
533 unsigned char* = 0, int target = -1);
534 virtual void min(signed char* data, int n,
535 signed char* = 0, int target = -1);
536 void min(double& data) { min(&data, 1); }
537 void min(int& data) { min(&data, 1); }
539
543 template <typename T>
544 void reduce(T*, int n, GrpReduce<T>&,
545 T*scratch = 0, int target = -1);
546 virtual void reduce(double*, int n, GrpReduce<double>&,
547 double*scratch = 0, int target = -1);
548 virtual void reduce(int*, int n, GrpReduce<int>&,
549 int*scratch = 0, int target = -1);
550 virtual void reduce(unsigned int*, int n, GrpReduce<unsigned int>&,
551 unsigned int*scratch = 0, int target = -1);
552 virtual void reduce(char*, int n, GrpReduce<char>&,
553 char*scratch = 0, int target = -1);
554 virtual void reduce(unsigned char*, int n, GrpReduce<unsigned char>&,
555 unsigned char*scratch = 0, int target = -1);
556 virtual void reduce(signed char*, int n, GrpReduce<signed char>&,
557 signed char*scratch = 0, int target = -1);
558 virtual void reduce(short*, int n, GrpReduce<short>&,
559 short*scratch = 0, int target = -1);
560 virtual void reduce(float*, int n, GrpReduce<float>&,
561 float*scratch = 0, int target = -1);
562 virtual void reduce(long*, int n, GrpReduce<long>&,
563 long*scratch = 0, int target = -1);
564 void reduce(double& data, GrpReduce<double>& r) { reduce(&data, 1, r); }
565 void reduce(int& data, GrpReduce<int>& r) { reduce(&data, 1, r); }
567
569 virtual void sync();
570
572 Ref<MachineTopology> topology() { return topology_; }
573
581 int classdesc_to_index(const ClassDesc*);
582 const ClassDesc* index_to_classdesc(int);
583 int nclass() const { return nclass_; }
585};
586
588 void *buf;
589 int size;
590 int type;
591 struct message_struct *p;
592 };
593typedef struct message_struct message_t;
594
595
599 private:
600 // Messages are stored in these linked lists
601 message_t *sync_messages;
602 message_t *type_messages;
603
604 void sendit(message_t *& messages, int dest, int msgtype, const void* buf, int bytes);
605 void recvit(message_t *& messages, int source, int type, void* buf, int bytes,
606 int& last_size, int& last_type);
607
608 public:
612
614 Ref<MessageGrp> split(int grpkey=0, int rankkey=0);
615 Ref<MessageGrp> subset(const std::set<int> &);
616
617 void raw_send(int target, const void* data, int nbyte);
618 void raw_sendt(int target, int type, const void* data, int nbyte,
619 bool rcvrdy=false);
620 void raw_recv(int sender, void* data, int nbyte,
621 MessageInfo *info=0);
622 void raw_recvt(int sender, int type, void* data, int nbyte,
623 MessageInfo *info=0);
624 void raw_bcast(void* data, int nbyte, int from);
625
626 void raw_nb_sendt(int sender, int type,
627 const void* data, int nbyte,
629 bool rcvrdy=false);
630 void raw_nb_recvt(int sender, int type,
631 void* data, int nbyte,
633 void wait(const MessageHandle&,
634 MessageInfo *info=0);
635
636 int probet(int sender, int type, MessageInfo *info=0);
637 void sync();
638};
639
640}
641
642#include <util/group/messaget.h>
643
644#endif
645
646
647// Local Variables:
648// mode: c++
649// c-file-style: "CLJ"
650// End:
This class is used to contain information about classes.
Definition class.h:147
Classes which need runtime information about themselves and their relationship to other classes can v...
Definition class.h:233
Definition message.h:85
Definition message.h:91
Definition message.h:97
Definition message.h:75
Definition message.h:109
Definition message.h:67
Definition message.h:59
Definition message.h:103
Definition message.h:43
Definition message.h:51
Definition message.h:135
Definition message.h:122
The MessageGrp abstract class provides a mechanism for moving data and objects between nodes in a par...
Definition message.h:120
static void set_default_messagegrp(const Ref< MessageGrp > &)
The default message group contains the primary message group to be used by an application.
void recv(int sender, int &data)
This receives a single integer datum.
Definition message.h:309
void recvt(int sender, int type, int &data)
This receives a single integer datum.
Definition message.h:335
Ref< MachineTopology > topology()
Return the MachineTopology object.
Definition message.h:572
void nb_recvt(int sender, int type, double &data, MessageHandle &handle)
This receives a single double datum.
Definition message.h:445
void nb_recvt(int sender, int type, int &data, MessageHandle &handle)
This receives a single integer datum.
Definition message.h:450
void initialize(int me, int n)
The classdesc_to_index_ and index_to_classdesc_ arrays cannot be initialized by the MessageGrp CTOR,...
int me()
Returns my processor number. In the range [0,n()).
Definition message.h:194
virtual void wait(const MessageHandle &handle, MessageInfo *info=0)=0
Wait for an operation to complete.
void send(int target, int data)
This sends a single integer datum.
Definition message.h:251
virtual void sync()
Synchronize all of the processors.
void sendt(int target, int type, double data, bool rcvrdy=false)
This sends a single double datum.
Definition message.h:282
virtual ~MessageGrp()
Destroy this MessageGrp.
void reduce(T *, int n, GrpReduce< T > &, T *scratch=0, int target=-1)
T must be a POD (plain old data) type so that it can be copied bytewise.
Definition messaget.h:116
virtual Ref< MessageGrp > clone(void)=0
Returns a copy of this MessageGrp specialization that provides an independent communication context.
void recvt(int sender, int type, double &data)
This receives a single double datum.
Definition message.h:331
static MessageGrp * get_default_messagegrp()
Returns the default message group.
int n()
Returns the number of processors.
Definition message.h:192
virtual Ref< MessageGrp > subset(const std::set< int > &)=0
Returns MessageGrp objects that are a subset of this MessageGrp.
static MessageGrp * initial_messagegrp(int &argc, char **&argv)
Create a message group.
virtual Ref< MessageGrp > split(int grpkey=0, int rankkey=0)=0
Returns MessageGrp objects that are a subset of this MessageGrp.
void recv(int sender, double &data)
This receives a single double datum.
Definition message.h:307
virtual int probet(int sender, int type, MessageInfo *info=0)=0
Ask if a given typed message has been received.
void send(int target, double data)
This sends a single double datum.
Definition message.h:249
void sendt(int target, int type, int data, bool rcvrdy=false)
This sends a single integer datum.
Definition message.h:285
ProcMessageGrp provides a concrete specialization of MessageGrp that supports only one node.
Definition message.h:598
int probet(int sender, int type, MessageInfo *info=0)
Ask if a given typed message has been received.
Ref< MessageGrp > split(int grpkey=0, int rankkey=0)
Returns MessageGrp objects that are a subset of this MessageGrp.
Ref< MessageGrp > clone(void)
Returns a copy of this MessageGrp specialization that provides an independent communication context.
Ref< MessageGrp > subset(const std::set< int > &)
Returns MessageGrp objects that are a subset of this MessageGrp.
void sync()
Synchronize all of the processors.
void wait(const MessageHandle &, MessageInfo *info=0)
Wait for an operation to complete.
A template class that maintains references counts.
Definition ref.h:361
Contains all MPQC code up to version 3.
Definition mpqcin.h:14
Definition message.h:587

Generated at Wed Sep 25 2024 02:45:30 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.