28 #ifndef _util_group_memory_h
29 #define _util_group_memory_h
33 #include <mpqc_config.h>
34 #include <util/class/class.h>
35 #include <util/group/thread.h>
39 #if 0 // this can be used to catch accidental conversions to int
41 friend size_t distsize_to_size(
const distsize_t &a);
42 friend distsize_t operator *(
const int &a,
const distsize_t &b);
43 friend distsize_t
operator +(
const int &a,
const distsize_t &b);
44 friend distsize_t operator -(
const int &a,
const distsize_t &b);
45 friend distsize_t operator /(
const int &a,
const distsize_t &b);
46 friend distsize_t operator %(
const int &a,
const distsize_t &b);
47 friend ostream&
operator <<(ostream& o,
const distsize_t &s);
51 distsize_t(): s(999999999999999LL) {}
52 distsize_t(
int a): s(a) {}
53 distsize_t(
unsigned int a): s(a) {}
54 distsize_t(
unsigned long long a): s(a) {}
55 distsize_t &operator =(
const distsize_t &a)
56 { s=a.s;
return *
this; }
57 distsize_t &operator +=(
const distsize_t &a)
58 { s+=a.s;
return *
this; }
59 distsize_t operator *(
const distsize_t &a)
const
61 distsize_t
operator +(
const distsize_t &a)
const
63 distsize_t operator -(
const distsize_t &a)
const
65 distsize_t operator /(
const distsize_t &a)
const
67 distsize_t operator %(
const distsize_t &a)
const
71 bool operator <=(
const distsize_t &a)
const
73 bool operator >(
const distsize_t &a)
const
75 bool operator >=(
const distsize_t &a)
const
79 distsize_t operator *(
const int &a)
const
83 distsize_t operator -(
const int &a)
const
85 distsize_t operator /(
const int &a)
const
87 distsize_t operator %(
const int &a)
const
90 inline distsize_t operator *(
const int &a,
const distsize_t &b)
92 inline distsize_t
operator +(
const int &a,
const distsize_t &b)
94 inline distsize_t operator -(
const int &a,
const distsize_t &b)
96 inline distsize_t operator /(
const int &a,
const distsize_t &b)
98 inline distsize_t operator %(
const int &a,
const distsize_t &b)
100 inline ostream&
operator <<(ostream& o,
const distsize_t &s) {
return o<<s.s; }
101 inline size_t distsize_to_size(
const distsize_t &a) {
return a.s;}
102 #elif defined(HAVE_LONG_LONG)
103 typedef unsigned long long distsize_t;
104 typedef long long distssize_t;
105 inline size_t distsize_to_size(
const distsize_t &a) {
return a;}
107 typedef unsigned long distsize_t;
108 typedef long distssize_t;
109 inline size_t distsize_to_size(
const distsize_t &a) {
return a;}
133 distsize_t *offsets_;
138 void obtain_local_lock(
size_t start,
size_t fence);
139 void release_local_lock(
size_t start,
size_t fence);
146 int me()
const {
return me_; }
148 int n()
const {
return n_; }
155 size_t localsize() {
return distsize_to_size(offsets_[me_+1]-offsets_[me_]); }
162 {
return distsize_to_size(offsets_[node+1] - offsets_[node]); }
164 distsize_t
offset(
int node) {
return offsets_[node]; }
200 virtual void sum_reduction(
double *data, distsize_t doffset,
size_t dsize);
214 virtual void sync() = 0;
274 template <
class data_t>
277 enum AccessType { None, Read, Write, ReadWrite };
278 AccessType accesstype_;
319 size_t length()
const {
return length_; }
325 template <
class data_t>
332 template <
class data_t>
336 if (accesstype_ != None) release();
337 data_ = (data_t *) grp_->obtain_writeonly(
sizeof(data_t)*offset,
338 sizeof(data_t)*length);
345 template <
class data_t>
349 if (accesstype_ != None) release();
350 data_ = (data_t *) grp_->obtain_readwrite(
sizeof(data_t)*offset,
351 sizeof(data_t)*length);
354 accesstype_ = ReadWrite;
358 template <
class data_t>
362 if (accesstype_ != None) release();
363 data_ = (data_t *) grp_->obtain_readonly(
sizeof(data_t)*offset,
364 sizeof(data_t)*length);
371 template <
class data_t>
375 if (node == -1) node = grp_->me();
376 return writeonly(offset + grp_->offset(node)/
sizeof(data_t), length);
379 template <
class data_t>
383 if (node == -1) node = grp_->me();
384 return readwrite(offset + grp_->offset(node)/
sizeof(data_t), length);
387 template <
class data_t>
391 if (node == -1) node = grp_->me();
392 return readonly(offset + grp_->offset(node)/
sizeof(data_t), length);
395 template <
class data_t>
399 if (accesstype_ == Write)
400 grp_->release_writeonly((data_t *)data_,
401 sizeof(data_t)*offset_,
sizeof(data_t)*length_);
402 if (accesstype_ == Read)
403 grp_->release_readonly(data_,
sizeof(data_t)*offset_,
404 sizeof(data_t)*length_);
405 if (accesstype_ == ReadWrite)
406 grp_->release_readwrite(data_,
sizeof(data_t)*offset_,
407 sizeof(data_t)*length_);
virtual void release_writeonly(void *data, distsize_t offset, size_t size)=0
This is called when write access is no longer needed.
virtual void * obtain_readonly(distsize_t offset, size_t size)=0
This gives read access to the memory location. No locking is done.
virtual void write(const void *data, distsize_t offset, size_t size)
This is used to write data directly.
virtual void sum_reduction(double *data, distsize_t doffset, size_t dsize)
Perform a sum reduction on double data.
int n() const
Returns how many nodes there are.
Definition: memory.h:148
data_t * readwrite(distsize_t offset, size_t length)
Request read write access to global memory at the global address offset and with size length.
Definition: memory.h:347
data_t * writeonly_on_node(size_t offset, size_t length, int node=-1)
This behaves like writeonly, except the offset is local to the node specified by node.
Definition: memory.h:373
distsize_t offset(int node)
Returns the global offset to node's memory.
Definition: memory.h:164
virtual Ref< MemoryGrp > clone(void)
Returns a copy of this MemoryGrp specialization that provides an independent communication context.
Ref< GaussianBasisSet > operator+(const Ref< GaussianBasisSet > &A, const Ref< GaussianBasisSet > &B)
Nonmember operator+ is more convenient to use than the member operator+.
virtual void print(std::ostream &o=ExEnv::out0()) const
Prints out information about the object.
const data_t * readonly_on_node(size_t offset, size_t length, int node=-1)
This behaves like readonly, except the offset is local to the node specified by node.
Definition: memory.h:389
virtual void catchup()
Processes outstanding requests.
virtual void release_readwrite(void *data, distsize_t offset, size_t size)=0
This is called when read/write access is no longer needed.
A template class that maintains references counts.
Definition: ref.h:361
static void set_default_memorygrp(const Ref< MemoryGrp > &)
The default memory group contains the primary memory group to be used by an application.
virtual 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.
virtual void * obtain_readwrite(distsize_t offset, size_t size)=0
Only one thread can have an unreleased obtain_readwrite at a time.
double * malloc_local_double(size_t ndouble)
Allocate double data that will be accessed locally only.
The MemoryGrp abstract class provides a way of accessing distributed memory in a parallel machine.
Definition: memory.h:120
size_t length() const
The length of the current bit of memory.
Definition: memory.h:319
virtual void deactivate()
Deactivate is called after the memory has been used.
int size(int node)
Returns the amount of memory residing on node.
Definition: memory.h:161
data_t * writeonly(distsize_t offset, size_t length)
Request write only access to global memory at the global address offset and with size length.
Definition: memory.h:334
virtual void * malloc_local(size_t nbyte)
Allocate data that will be accessed locally only.
The MemoryGrpBuf class provides access to pieces of the global shared memory that have been obtained ...
Definition: memory.h:275
virtual void sync()=0
Synchronizes all the nodes.
virtual void * obtain_writeonly(distsize_t offset, size_t size)=0
This gives write access to the memory location. No locking is done.
virtual void free_local(void *&data)
Free data that was allocated with malloc_local, and set the pointer to 0.
std::vector< unsigned int > operator<<(const GaussianBasisSet &B, const GaussianBasisSet &A)
computes a map from basis functions in A to the equivalent basis functions in B.
size_t localsize()
Returns the amount of memory residing locally on me().
Definition: memory.h:155
int me() const
Returns who I am.
Definition: memory.h:146
void free_local_double(double *&data)
Free data that was allocated with malloc_local_double, and set the pointer to 0
static MemoryGrp * get_default_memorygrp()
Returns the default memory group.
const data_t * readonly(distsize_t offset, size_t length)
Request read only access to global memory at the global address offset and with size length.
Definition: memory.h:360
data_t * readwrite_on_node(size_t offset, size_t length, int node=-1)
This behaves like readwrite, except the offset is local to the node specified by node.
Definition: memory.h:381
virtual void * localdata()=0
Returns a pointer to the local data.
void release()
Release the access to the chunk of global memory that was obtained with writeonly,...
Definition: memory.h:397
Classes which need runtime information about themselves and their relationship to other classes can v...
Definition: class.h:233
bool operator<(const Space< Spin > &a, const Space< Spin > &b)
Compare two spaces by their rank.
Definition: subspace.hpp:44
static std::ostream & out0()
Return an ostream that writes from node 0.
static MemoryGrp * initial_memorygrp()
Create a memory group.
virtual void set_localsize(size_t)=0
Set the size of locally held memory.
MemoryGrpBuf(const Ref< MemoryGrp > &)
Creates a new MemoryGrpBuf given a MemoryGrp reference.
Definition: memory.h:326
bool operator==(const Atom &a, const Atom &b)
virtual void activate()
Activate is called before the memory is to be used.
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
virtual void release_readonly(void *data, distsize_t offset, size_t size)=0
This is called when read access is no longer needed.
distsize_t localoffset()
Returns the global offset to this node's memory.
Definition: memory.h:159
distsize_t totalsize()
Returns the sum of all memory allocated on all nodes.
Definition: memory.h:166
Generated at Sun Jan 26 2020 23:24:01 for MPQC
3.0.0-alpha using the documentation package Doxygen
1.8.16.