MPQC  3.0.0-alpha
memamsg.h
1 //
2 // memamsg.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_memamsg_h
29 #define _util_group_memamsg_h
30 
31 #include <iostream>
32 
33 #include <util/group/memmsg.h>
34 
35 namespace sc {
36 
39  public:
40  enum Request { Deactivate, Sync, Retrieve, Replace, DoubleSum };
41  private:
42  struct {
43  long offset;
44  long size;
45  Request request;
46  int node;
47  int serial_number;
48  int lock;
49  } data_;
50  public:
52  MemoryDataRequest(Request r, int node = 0, long offset = 0, long size = 0,
53  int lock = 0, int serial = 0);
54  void assign(Request r, int node, long offset, long size,
55  int lock, int serial);
56  void *data() const { return (void *) &data_; }
57  int nbytes() const { return sizeof(data_); }
58 
59  const char *request_string() const;
60 
61  MemoryDataRequest::Request request() const { return data_.request; }
62  int node() const { return data_.node; }
63  long offset() const { return data_.offset; }
64  long size() const { return data_.size; }
65  int serial_number() const { return data_.serial_number; }
66  int lock() const { return data_.lock; }
67 
68  int touches_data() const {return request()!=Deactivate&&request()!=Sync;}
69 
70  // Sync messages only define one datum besides type and node
71  int reactivate() const { return data_.offset; }
72 
73  void operator =(const MemoryDataRequest &r);
74 
75  void print(const char* msg = 0, std::ostream & o = ExEnv::out0()) const;
76 };
77 
80  public:
81  enum { MaxDepth = 1024 };
82  private:
83  MemoryDataRequest q_[MaxDepth];
84  int n_;
85  public:
86  MemoryDataRequestQueue(): n_(0) {}
87  int n() const { return n_; }
88  void push(MemoryDataRequest&);
89  void pop(MemoryDataRequest&);
90 
91  MemoryDataRequest& operator[](int i) { return q_[i]; }
92  void clear() { n_ = 0; }
93 };
94 
98  protected:
99  char *data_;
100 
101  virtual void retrieve_data(void *, int node, long offset, long size,
102  int lock) = 0;
103  virtual void replace_data(void *, int node, long offset, long size,
104  int unlock) = 0;
105  virtual void sum_data(double *data, int node, long doffset, long dsize) = 0;
106  public:
110 
111  void set_localsize(size_t);
112  void *localdata();
113 
114  void *obtain_writeonly(distsize_t offset, size_t size);
115  void *obtain_readwrite(distsize_t offset, size_t size);
116  void *obtain_readonly(distsize_t offset, size_t size);
117  void release_readonly(void *data, distsize_t offset, size_t size);
118  void release_writeonly(void *data, distsize_t offset, size_t size);
119  void release_readwrite(void *data, distsize_t offset, size_t size);
120  void write(const void* data, distsize_t offset, size_t size);
121 
122  void sum_reduction(double *data, distsize_t doffset, size_t dsize);
123  void sum_reduction_on_node(double *data, size_t doffset, size_t dsize,
124  int node = -1);
125 
126  void print(std::ostream &o = ExEnv::out0()) const;
127 };
128 
129 }
130 
131 #endif
132 
133 // Local Variables:
134 // mode: c++
135 // c-file-style: "CLJ"
136 // End:
sc::ActiveMsgMemoryGrp::set_localsize
void set_localsize(size_t)
Set the size of locally held memory.
sc::ActiveMsgMemoryGrp::release_writeonly
void release_writeonly(void *data, distsize_t offset, size_t size)
This is called when write access is no longer needed.
sc::MemoryGrp::offset
distsize_t offset(int node)
Returns the global offset to node's memory.
Definition: memory.h:164
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::MemoryDataRequest
This is a help class used by ActiveMsgMemoryGrp.
Definition: memamsg.h:38
sc::ActiveMsgMemoryGrp::obtain_readonly
void * obtain_readonly(distsize_t offset, size_t size)
This gives read access to the memory location. No locking is done.
sc::ActiveMsgMemoryGrp::obtain_writeonly
void * obtain_writeonly(distsize_t offset, size_t size)
This gives write access to the memory location. No locking is done.
sc::MemoryGrp::size
int size(int node)
Returns the amount of memory residing on node.
Definition: memory.h:161
sc::ActiveMsgMemoryGrp::release_readwrite
void release_readwrite(void *data, distsize_t offset, size_t size)
This is called when read/write access is no longer needed.
sc::ActiveMsgMemoryGrp::obtain_readwrite
void * obtain_readwrite(distsize_t offset, size_t size)
Only one thread can have an unreleased obtain_readwrite at a time.
sc::ActiveMsgMemoryGrp::localdata
void * localdata()
Returns a pointer to the local data.
sc::MemoryDataRequestQueue
This is a help class used by ActiveMsgMemoryGrp.
Definition: memamsg.h:79
sc::ActiveMsgMemoryGrp::release_readonly
void release_readonly(void *data, distsize_t offset, size_t size)
This is called when read access is no longer needed.
sc::ActiveMsgMemoryGrp::print
void print(std::ostream &o=ExEnv::out0()) const
Prints out information about the object.
sc::ActiveMsgMemoryGrp::write
void write(const void *data, distsize_t offset, size_t size)
This is used to write data directly.
sc::ActiveMsgMemoryGrp
The ActiveMsgMemoryGrp abstract class specializes the MsgMemoryGrp class.
Definition: memamsg.h:97
sc::ActiveMsgMemoryGrp::sum_reduction
void sum_reduction(double *data, distsize_t doffset, size_t dsize)
Perform a sum reduction on double data.
sc::ActiveMsgMemoryGrp::sum_reduction_on_node
void sum_reduction_on_node(double *data, size_t doffset, size_t dsize, int node=-1)
Perform a sum reduction on double data localized to a single node.
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::MsgMemoryGrp
A MsgMemoryGrp that initializes its data using a messagegrp.
Definition: memmsg.h:37
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.