MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
mstate.h
1//
2// mstate.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_mstate_h
29#define _util_group_mstate_h
30
31#include <util/state/state.h>
32#include <util/state/statein.h>
33#include <util/state/stateout.h>
34#include <util/group/message.h>
35
36namespace sc {
37
41class MsgStateSend: public StateOut {
42 private:
43 // do not allow copy constructor or assignment
45 void operator=(const MsgStateSend&);
46 protected:
48 int nbuf; // the number of bytes used in the buffer
49 int bufsize; // the allocated size of the data buffer
50 char* buffer; // the data buffer
51 char* send_buffer; // the buffer used to send data (includes nbuf)
52 int nheader; // nbuf + nheader = the number of bytes in send_buffer to send
53 int* nbuf_buffer; // the pointer to the nbuf stored in the buffer
54
55 int put_array_void(const void*, int);
56 public:
58 virtual ~MsgStateSend();
59
61 virtual void flush() = 0;
62
65 void set_buffer_size(int);
66
69 int put(const ClassDesc*);
70 int put(const std::string&);
71 int put(char r);
72 int put(unsigned int r);
73 int put(int r);
74 int put(unsigned long r);
75 int put(bool r);
76 int put(long r);
77 int put(float r);
78 int put(double r);
79 int put(const char*,int);
80 int put(const int*,int);
81 int put(const unsigned int*,int);
82 int put(const long*,int);
83 int put(const unsigned long*,int);
84 int put(const float*,int);
85 int put(const double*,int);
86};
87
91class MsgStateBufRecv: public StateIn {
92 private:
93 // do not allow copy constructor or assignment
95 void operator=(const MsgStateBufRecv&);
96 protected:
98 int nbuf; // the number of bytes used in the buffer
99 int ibuf; // the current pointer withing the buffer
100 int bufsize; // the allocated size of the buffer
101 char* buffer; // the data buffer
102 char* send_buffer; // the buffer used to send data (includes nbuf)
103 int nheader; // nbuf + nheader = the number of bytes in send_buffer to send
104 int* nbuf_buffer; // the pointer to the nbuf stored in the buffer
105
106 int get_array_void(void*,int);
107
109 virtual void next_buffer() = 0;
110 public:
115
116 virtual ~MsgStateBufRecv();
117
121};
122
126 private:
127 // do not allow copy constructor or assignment
129 void operator=(const MsgStateRecv&);
130 public:
133
134 virtual ~MsgStateRecv();
135
139 int version(const ClassDesc*);
140
143 int get(const ClassDesc**);
144 int get(std::string&);
145 int get(char&r, const char *key = 0);
146 int get(unsigned int&r, const char *key = 0);
147 int get(int&r, const char *key = 0);
148 int get(unsigned long&r, const char *key = 0);
149 int get(long&r, const char *key = 0);
150 int get(bool&r, const char *key = 0);
151 int get(float&r, const char *key = 0);
152 int get(double&r, const char *key = 0);
153 int get(char*&);
154 int get(unsigned int*&);
155 int get(int*&);
156 int get(unsigned long*&);
157 int get(long*&);
158 int get(float*&);
159 int get(double*&);
160};
161
165class StateSend: public MsgStateSend {
166 private:
167 // do not allow copy constructor or assignment
168 StateSend(const StateSend&);
169 void operator=(const StateSend&);
170 private:
171 int type_;
172 int target_;
173 public:
176
177 ~StateSend();
179 void target(int);
181 int get_target() const { return target_; }
183 void type(int);
185 int get_type() const { return type_; }
187 void flush();
188};
189
193class StateRecv: public MsgStateRecv {
194 private:
195 // do not allow copy constructor or assignment
196 StateRecv(const StateRecv&);
197 void operator=(const StateRecv&);
198 private:
199 int source_;
200 int type_;
201 int last_source_;
202 int last_type_;
203 protected:
205 public:
209 void source(int);
211 void type(int);
216};
217
222 private:
223 // do not allow copy constructor or assignment
225 void operator=(const BcastStateSend&);
226 public:
229
232 void flush();
233};
234
239 private:
240 // do not allow copy constructor or assignment
242 void operator=(const BcastStateRecv&);
243 protected:
244 int source_;
246 public:
250 void source(int s);
251};
252
257 private:
258 BcastStateRecv *recv_;
259 BcastStateSend *send_;
260 public:
262 BcastState(const Ref<MessageGrp> &, int source = 0);
263
264 ~BcastState();
265
271 void bcast(int &);
272 void bcast(double &);
273 void bcast(int *&, int);
274 void bcast(double *&, int);
275 template <class T> void bcast(Ref<T>&a)
276 {
277 if (recv_) {
278 a << SavableState::restore_state(*recv_);
279 }
280 else if (send_) {
282 }
283 }
285
288 void flush();
289
293
296};
297
302 private:
303 // do not allow copy constructor or assignment
305 void operator=(const BcastStateRecv&);
306 protected:
307 int opened_;
308 int file_position_;
309 std::streambuf *buf_;
310
312 int get_array_void(void*, int);
313 public:
317 BcastStateInBin(const Ref<MessageGrp>&, const char *filename);
318
320
321 virtual int open(const char *name);
322 virtual void close();
323
324 void seek(int loc);
325 int seekable();
326 int tell();
328};
329
330}
331
332#endif
333
334// Local Variables:
335// mode: c++
336// c-file-style: "CLJ"
337// End:
BcastStateBin reads a file in written by StateInBin on node 0 and broadcasts it to all nodes so state...
Definition mstate.h:301
void seek(int loc)
Set the current position in the file.
int use_directory()
Returns true of this object uses a directory.
BcastStateInBin(const Ref< KeyVal > &)
Create the BcastStateRecv using the default MessageGrp.
int seekable()
Return non-zero if seek does anything sensible.
void next_buffer()
Specializations must implement next_buffer().
int tell()
Return the current position in the file.
BcastStateInBin(const Ref< MessageGrp > &, const char *filename)
Create the BcastStateRecv.
BcastStateRecv does the receive part of a broadcast of an object to all nodes.
Definition mstate.h:238
BcastStateRecv(const Ref< MessageGrp > &, int source=0)
Create the BcastStateRecv.
void next_buffer()
Specializations must implement next_buffer().
void source(int s)
Set the source node.
BcastStateSend does the send part of a broadcast of an object to all nodes.
Definition mstate.h:221
void flush()
Flush the data remaining in the buffer.
BcastStateSend(const Ref< MessageGrp > &)
Create the BcastStateSend.
This creates and forwards/retrieves data from either a BcastStateRecv or a BcastStateSend depending o...
Definition mstate.h:256
void flush()
Force data to be written.
void forget_references()
Call the StateOut or StateIn forget_references member.
void set_buffer_size(int)
Controls the amount of data that is buffered before it is sent.
BcastState(const Ref< MessageGrp > &, int source=0)
Create a BcastState object. The default source is node 0.
This class is used to contain information about classes.
Definition class.h:147
The MsgStateBufRecv is an abstract base class that buffers objects sent through a MessageGrp.
Definition mstate.h:91
virtual void next_buffer()=0
Specializations must implement next_buffer().
MsgStateBufRecv(const Ref< MessageGrp > &)
MsgStateBufRecv can be initialized with a MessageGrp.
void set_buffer_size(int)
The buffer size of statein and stateout objects that communicate with each other must match.
MsgStateBufRecv()
Use the default MessageGrp.
The MsgStateRecv is an abstract base class that receives objects from nodes in a MessageGrp.
Definition mstate.h:125
MsgStateRecv(const Ref< MessageGrp > &)
MsgStateRecv must be initialized with a MessageGrp.
int version(const ClassDesc *)
Returns the version of the ClassDesc.
int get(const ClassDesc **)
I only need to override get(ClassDesc**) but C++ will hide all of the other get's so I must override ...
The MsgStateSend is an abstract base class that sends objects to nodes in a MessageGrp.
Definition mstate.h:41
void set_buffer_size(int)
The buffer size of statein and stateout objects that communicate with each other must match.
virtual void flush()=0
Specializations must implement flush().
int put(const ClassDesc *)
I only need to override put(const ClassDesc*) but C++ will hide all of the other put's so I must over...
A template class that maintains references counts.
Definition ref.h:361
T * pointer() const
Returns a pointer the reference counted object.
Definition ref.h:413
static SavableState * restore_state(StateIn &si)
Restores objects saved with save_state.
void save_state(StateOut &)
Save the state of the object as specified by the StateOut object.
Restores fundamental and user-defined types from images created with StateOut.
Definition statein.h:79
Serializes fundamental and user-defined types.
Definition stateout.h:71
StateRecv is a concrete specialization of MsgStateRecv that does the receive part of point to point c...
Definition mstate.h:193
void source(int)
Specify the source node.
int last_type()
Return the type of the last message received.
void type(int)
Specify the message type.
int last_source()
Return the source of the last message received.
StateRecv(const Ref< MessageGrp > &)
Create a StateRecv given a MessageGrp.
void next_buffer()
Specializations must implement next_buffer().
StateSend is a concrete specialization of MsgStateSend that does the send part of point to point comm...
Definition mstate.h:165
int get_target() const
Return the target.
Definition mstate.h:181
void type(int)
Specify the type.
void flush()
Flush the buffer.
StateSend(const Ref< MessageGrp > &)
Create a StateSend given a MessageGrp.
void target(int)
Specify the target node.
int get_type() const
Return the type.
Definition mstate.h:185
Contains all MPQC code up to version 3.
Definition mpqcin.h:14

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