📄 message.h
字号:
//// message.h//// Copyright (C) 1996 Limit Point Systems, Inc.//// Author: Curtis Janssen <cljanss@limitpt.com>// Maintainer: LPS//// This file is part of the SC Toolkit.//// The SC Toolkit is free software; you can redistribute it and/or modify// it under the terms of the GNU Library General Public License as published by// the Free Software Foundation; either version 2, or (at your option)// any later version.//// The SC Toolkit is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU Library General Public License for more details.//// You should have received a copy of the GNU Library General Public License// along with the SC Toolkit; see the file COPYING.LIB. If not, write to// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.//// The U.S. Government is granted a limited license as per AL 91-7.//#ifdef __GNUC__#pragma interface#endif#ifndef _util_group_message_h#define _util_group_message_h#include <map>#include <math.h>#include <util/class/class.h>#include <util/state/state.h>#include <util/keyval/keyval.h>#include <util/group/topology.h>namespace sc {template <class T>class GrpReduce { public: virtual ~GrpReduce() {}; virtual void reduce(T*target, T*data, int n) = 0;};template <class T>class GrpSumReduce: public GrpReduce<T> { public: void reduce(T*target, T*data, int nelement);};template <class T>class GrpMinReduce: public GrpReduce<T> { public: void reduce(T*target, T*data, int nelement);};template <class T>class GrpMaxReduce: public GrpReduce<T> { public: void reduce(T*target, T*data, int nelement);};template <class T>class GrpArithmeticAndReduce: public GrpReduce<T> { public: void reduce(T*target, T*data, int nelement);};template <class T>class GrpArithmeticOrReduce: public GrpReduce<T> { public: void reduce(T*target, T*data, int nelement);};template <class T>class GrpArithmeticXOrReduce: public GrpReduce<T> { public: void reduce(T*target, T*data, int nelement);};template <class T>class GrpProductReduce: public GrpReduce<T> { public: void reduce(T*target, T*data, int nelement);};template <class T>class GrpFunctionReduce: public GrpReduce<T> { private: void (*func_)(T*target,T*data,int nelement); public: GrpFunctionReduce(void(*func)(T*,T*,int)):func_(func) {} void reduce(T*target, T*data, int nelement);};/** The MessageGrp abstract class provides a mechanism for moving data and objects between nodes in a parallel machine. */class MessageGrp: public DescribedClass { private: // These are initialized by the initialize() member (see below). int me_; int n_; int nclass_; int gop_max_; std::map<ClassDescP,int> classdesc_to_index_; ClassDescP *index_to_classdesc_; protected: /** The classdesc_to_index_ and index_to_classdesc_ arrays cannot be initialized by the MessageGrp CTOR, because the MessageGrp specialization has not yet been initialized and communication is not available. CTOR's of specializations of MessageGrp must call the initialize member in their body to complete the initialization process. */ void initialize(int me, int n); Ref<MachineTopology> topology_; int debug_; public: MessageGrp(); MessageGrp(const Ref<KeyVal>&); virtual ~MessageGrp(); /// Returns the number of processors. int n() { return n_; } /// Returns my processor number. In the range [0,n()). int me() { return me_; } /** Returns a copy of this MessageGrp specialization that provides an independent communication context. */ virtual Ref<MessageGrp> clone(void)=0; /** The default message group contains the primary message group to be used by an application. */ static void set_default_messagegrp(const Ref<MessageGrp>&); /// Returns the default message group. static MessageGrp* get_default_messagegrp(); /** Create a message group. This routine looks for a -messagegrp argument, then the environmental variable MESSAGEGRP to decide which specialization of MessageGrp would be appropriate. The argument to -messagegrp should be either string for a ParsedKeyVal constructor or a classname. If this returns null, it is up to the programmer to create a MessageGrp. */ static MessageGrp* initial_messagegrp(int &argc, char** &argv); /** Send messages sequentially to the target processor. Similar members exist for each of the basic types. */ virtual void send(int target, double* data, int ndata); virtual void send(int target, unsigned int* data, int ndata); virtual void send(int target, int* data, int ndata); virtual void send(int target, char* data, int nbyte); virtual void send(int target, unsigned char* data, int nbyte); virtual void send(int target, signed char* data, int nbyte); virtual void send(int target, short* data, int ndata); virtual void send(int target, long* data, int ndata); virtual void send(int target, float* data, int ndata); void send(int target, double data) { send(target,&data,1); } void send(int target, int data) { send(target,&data,1); } virtual void raw_send(int target, void* data, int nbyte) = 0; /** Send typed messages to the target processor. Similar members exist for each of the basic types. */ virtual void sendt(int target, int type, double* data, int ndata); virtual void sendt(int target, int type, unsigned int* data, int ndata); virtual void sendt(int target, int type, int* data, int ndata); virtual void sendt(int target, int type, char* data, int nbyte); virtual void sendt(int target, int type, unsigned char* data, int nbyte); virtual void sendt(int target, int type, signed char* data, int nbyte); virtual void sendt(int target, int type, short* data, int ndata); virtual void sendt(int target, int type, long* data, int ndata); virtual void sendt(int target, int type, float* data, int ndata); void sendt(int target, int type, double data) {sendt(target,type,&data,1);} void sendt(int target, int type, int data) {sendt(target,type,&data,1);} virtual void raw_sendt(int target, int type, void* data, int nbyte) = 0; /** Receive messages sent sequentually from the sender. Similar members exist for each of the basic types. */ virtual void recv(int sender, double* data, int ndata); virtual void recv(int sender, unsigned int* data, int ndata); virtual void recv(int sender, int* data, int ndata); virtual void recv(int sender, char* data, int nbyte); virtual void recv(int sender, unsigned char* data, int nbyte); virtual void recv(int sender, signed char* data, int nbyte); virtual void recv(int sender, short* data, int ndata); virtual void recv(int sender, long* data, int ndata); virtual void recv(int sender, float* data, int ndata); void recv(int sender, double& data) { recv(sender,&data,1); } void recv(int sender, int& data) { recv(sender,&data,1); } virtual void raw_recv(int sender, void* data, int nbyte) = 0; /** Receive messages sent by type. Similar members exist for each of the basic types. */ virtual void recvt(int type, double* data, int ndata); virtual void recvt(int type, unsigned int* data, int ndata); virtual void recvt(int type, int* data, int ndata); virtual void recvt(int type, char* data, int nbyte); virtual void recvt(int type, unsigned char* data, int nbyte); virtual void recvt(int type, signed char* data, int nbyte); virtual void recvt(int type, short* data, int ndata);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -