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 Request { Deactivate, Sync, Retrieve, Replace, DoubleSum };
00044   private:
00045     struct {
00046         long offset;
00047         long size;
00048         Request request;
00049         int node;
00050         int serial_number;
00051         int lock;
00052     } data_;
00053   public:
00054     MemoryDataRequest() {}
00055     MemoryDataRequest(Request r, int node = 0, long offset = 0, long size = 0,
00056                       int lock = 0, int serial = 0);
00057     void assign(Request r, int node, long offset, long size,
00058                 int lock, int serial);
00059     void *data() const { return (void *) &data_; }
00060     int nbytes() const { return sizeof(data_); }
00061 
00062     const char *request_string() const;
00063 
00064     MemoryDataRequest::Request request() const { return data_.request; }
00065     int node() const { return data_.node; }
00066     long offset() const { return data_.offset; }
00067     long size() const { return data_.size; }
00068     int serial_number() const { return data_.serial_number; }
00069     int lock() const { return data_.lock; }
00070 
00071     int touches_data() const {return request()!=Deactivate&&request()!=Sync;}
00072 
00073     // Sync messages only define one datum besides type and node
00074     int reactivate() const { return data_.offset; }
00075 
00076     void operator =(const MemoryDataRequest &r);
00077 
00078     void print(const char* msg = 0, std::ostream & o = ExEnv::out0()) const;
00079 };
00080 
00081 class MemoryDataRequestQueue {
00082   public:
00083     enum { MaxDepth = 1024 };
00084   private:
00085     MemoryDataRequest q_[MaxDepth];
00086     int n_;
00087   public:
00088     MemoryDataRequestQueue(): n_(0) {}
00089     int n() const { return n_; }
00090     void push(MemoryDataRequest&);
00091     void pop(MemoryDataRequest&);
00092 
00093     MemoryDataRequest& operator[](int i) { return q_[i]; }
00094     void clear() { n_ = 0; }
00095 };
00096 
00099 class ActiveMsgMemoryGrp : public MsgMemoryGrp {
00100   protected:
00101     char *data_;
00102 
00103     virtual void retrieve_data(void *, int node, long offset, long size,
00104                                int lock) = 0;
00105     virtual void replace_data(void *, int node, long offset, long size,
00106                               int unlock) = 0;
00107     virtual void sum_data(double *data, int node, long doffset, long dsize) = 0;
00108   public:
00109     ActiveMsgMemoryGrp(const Ref<MessageGrp>& msg);
00110     ActiveMsgMemoryGrp(const Ref<KeyVal>&);
00111     ~ActiveMsgMemoryGrp();
00112 
00113     void set_localsize(size_t);
00114     void *localdata();
00115 
00116     void *obtain_writeonly(distsize_t offset, int size);
00117     void *obtain_readwrite(distsize_t offset, int size);
00118     void *obtain_readonly(distsize_t offset, int size);
00119     void release_readonly(void *data, distsize_t offset, int size);
00120     void release_writeonly(void *data, distsize_t offset, int size);
00121     void release_readwrite(void *data, distsize_t offset, int size);
00122 
00123     void sum_reduction(double *data, distsize_t doffset, int dsize);
00124     void sum_reduction_on_node(double *data, size_t doffset, int dsize,
00125                                int node = -1);
00126 
00127     void print(std::ostream &o = ExEnv::out0()) const;
00128 };
00129 
00130 }
00131 
00132 #endif
00133 
00134 // Local Variables:
00135 // mode: c++
00136 // c-file-style: "CLJ"
00137 // End:

Generated at Wed Sep 5 14:02:30 2007 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.5.2.
These pages are hosted on SourceForge.net