Main Page Class Hierarchy Compound List File List Compound Members Related Pages

# memamsg.h

    00001 //
    00002 // memamsg.h
    00003 //
    00004 // Copyright (C) 1996 Limit Point Systems, Inc.
    00005 //
    00006 // Author: Curtis Janssen <cljanss@limitpt.com>
    00007 // Maintainer: LPS
    00008 //
    00009 // This file is part of the SC Toolkit.
    00010 //
    00011 // The SC Toolkit is free software; you can redistribute it and/or modify
    00012 // it under the terms of the GNU Library General Public License as published by
    00013 // the Free Software Foundation; either version 2, or (at your option)
    00014 // any later version.
    00015 //
    00016 // The SC Toolkit is distributed in the hope that it will be useful,
    00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00019 // GNU Library General Public License for more details.
    00020 //
    00021 // You should have received a copy of the GNU Library General Public License
    00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
    00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    00024 //
    00025 // The U.S. Government is granted a limited license as per AL 91-7.
    00026 //
    00027
    00028 #ifdef __GNUC__
    00029 #pragma interface
    00030 #endif
    00031
    00032 #ifndef _util_group_memamsg_h
    00033 #define _util_group_memamsg_h
    00034
    00035 #include <iostream>
    00036
    00037 #include <util/group/memmsg.h>
    00038
    00039 namespace sc {
    00040
    00041 class MemoryDataRequest {
    00042   public:
    00043     enum { NData = 6 };
    00044     enum Request { Deactivate, Sync, Retrieve, Replace, DoubleSum };
    00045   private:
    00046     int data_[NData];
    00047   public:
    00048     MemoryDataRequest() {}
    00049     MemoryDataRequest(Request r, int node = 0, int offset = 0, int size = 0,
    00050                       int lock = 0, int serial = 0);
    00051     void assign(Request r, int node, int offset, int size,
    00052                 int lock, int serial);
    00053     void *data() const { return (void *) data_; }
    00054     int nbytes() const { return sizeof(int)*NData; }
    00055
    00056     const char *request_string() const;
    00057
    00058     MemoryDataRequest::Request request() const { return (Request) data_[0]; }
    00059     int node() const { return data_[1]; }
    00060     int offset() const { return data_[2]; }
    00061     int size() const { return data_[3]; }
    00062     int serial_number() const { return data_[4]; }
    00063     int lock() const { return data_[5]; }
    00064
    00065     int touches_data() const {return request()!=Deactivate&&request()!=Sync;}
    00066
    00067     // Sync messages only define one datum besides type and node
    00068     int reactivate() const { return data_[2]; }
    00069
    00070     void operator =(const MemoryDataRequest &r);
    00071
    00072     void print(const char* msg = 0, std::ostream & o = ExEnv::out0()) const;
    00073 };
    00074
    00075 class MemoryDataRequestQueue {
    00076   public:
    00077     enum { MaxDepth = 1024 };
    00078   private:
    00079     MemoryDataRequest q_[MaxDepth];
    00080     int n_;
    00081   public:
    00082     MemoryDataRequestQueue(): n_(0) {}
    00083     int n() const { return n_; }
    00084     void push(MemoryDataRequest&);
    00085     void pop(MemoryDataRequest&);
    00086
    00087     MemoryDataRequest& operator[](int i) { return q_[i]; }
    00088     void clear() { n_ = 0; }
    00089 };
    00090
    00093 class ActiveMsgMemoryGrp : public MsgMemoryGrp {
    00094   protected:
    00095     char *data_;
    00096
    00097     virtual void retrieve_data(void *, int node, int offset, int size,
    00098                                int lock) = 0;
    00099     virtual void replace_data(void *, int node, int offset, int size,
    00100                               int unlock) = 0;
    00101     virtual void sum_data(double *data, int node, int doffset, int dsize) = 0;
    00102   public:
    00103     ActiveMsgMemoryGrp(const Ref<MessageGrp>& msg);
    00104     ActiveMsgMemoryGrp(const Ref<KeyVal>&);
    00105     ~ActiveMsgMemoryGrp();
    00106
    00107     void set_localsize(size_t);
    00108     void *localdata();
    00109
    00110     void *obtain_writeonly(distsize_t offset, int size);
    00111     void *obtain_readwrite(distsize_t offset, int size);
    00112     void *obtain_readonly(distsize_t offset, int size);
    00113     void release_readonly(void *data, distsize_t offset, int size);
    00114     void release_writeonly(void *data, distsize_t offset, int size);
    00115     void release_readwrite(void *data, distsize_t offset, int size);
    00116
    00117     void sum_reduction(double *data, distsize_t doffset, int dsize);
    00118     void sum_reduction_on_node(double *data, size_t doffset, int dsize,
    00119                                int node = -1);
    00120
    00121     void print(std::ostream &o = ExEnv::out0()) const;
    00122 };
    00123
    00124 }
    00125
    00126 #endif
    00127
    00128 // Local Variables:
    00129 // mode: c++
    00130 // c-file-style: "CLJ"
    00131 // End: