MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
memregion.h
1//
2// memregion.h
3//
4// Copyright (C) 2008 Edward Valeev
5//
6// Author: Edward Valeev <evaleev@vt.edu>
7// Maintainer: EV
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_memregion_h
29#define _util_group_memregion_h
30
31#include <list>
32#include <vector>
33#include <memory>
34#include <sys/types.h>
35
36#include <util/group/memory.h>
37
38namespace sc {
39
47 public:
49 MemoryGrpRegion(const Ref<MemoryGrp>& mem, size_t mem_start, size_t max_size);
51 MemoryGrpRegion(const Ref<MemoryGrp>& mem, size_t max_size);
53
54 void set_localsize(size_t);
55 void* localdata();
56
57 void* obtain_readwrite(distsize_t offset, size_t size);
58 void* obtain_readonly(distsize_t offset, size_t size);
59 void* obtain_writeonly(distsize_t offset, size_t size);
60 void release_readonly(void* data, distsize_t offset, size_t size);
61 void release_writeonly(void* data, distsize_t offset, size_t size);
62 void release_readwrite(void* data, distsize_t offset, size_t size);
63 // to implement sum_reduction as in ActiveMsgMemoryGrp (i.e., with locking one node at a time)
64 // need the analog of MemoryIter
65 // TODO implement MemoryRegionIter
66 // for now use the less efficient MemoryGrp version which uses obtain_readwrite, hence may lock multiple nodes
67 //void sum_reduction(double *data, distsize_t doffset, int dsize);
68 void sum_reduction_on_node(double *data, size_t doffset, size_t dsize, int node=-1);
69
70 void activate();
71 void deactivate();
72 void sync();
73 void catchup();
74 void* malloc_local(size_t nbytes);
75 void free_local(void*& data);
76
78 void print(std::ostream &o=ExEnv::out0()) const;
79
80 private:
81
82 // change to 0 if want the most general implementation, but semantics of double-specific functions (sum_reduction_on_node, etc.) will throw then
83 static const int only_allow_double_aligned_regions_ = 1;
84
90 static const int classdebug_ = 0;
91 static int classdebug() { return classdebug_; }
92
93 // init() should be called in every constructor to finish up construction duties
94 void init();
95
97 class LocalRegion {
98 public:
99 LocalRegion(size_t start, size_t size) : start_(start), size_(size) {}
100 size_t start() const { return start_; }
101 size_t size() const { return size_; }
102 bool operator==(const LocalRegion& other) const {
103 return start() == other.start() && size() == other.size();
104 }
105 bool operator>(const LocalRegion& other) const {
106 return start() > other.start();
107 }
108 private:
109 size_t start_;
110 size_t size_;
111 };
112 typedef std::list<LocalRegion> LocalRegions;
113
114 Ref<MemoryGrp> host_;
115 LocalRegion reserve_; // reserved space
116 std::vector<distsize_t> host_offsets_; // start of regions on each node using the host MemoryGrp coordinates
117 // converts offset from this object's coordinates to host coordinates
118 distsize_t offset_to_host_offset(const distsize_t& offset) const;
119
121 class HostToRegionsMap {
122 public:
123 HostToRegionsMap();
124 ~HostToRegionsMap();
125 void insert(const MemoryGrp* host, const LocalRegion& region);
126 void erase(const MemoryGrp* host, const LocalRegion& region);
128 size_t find_free(const MemoryGrp* host, size_t sz) const;
129 private:
130 const LocalRegions* regions(const MemoryGrp* host) const;
131 typedef std::map<const MemoryGrp*,LocalRegions*> ImplType;
132 ImplType impl_;
133 Ref<ThreadLock> lock_;
134 };
135 static HostToRegionsMap map_;
136
137};
138
139}
140
141#endif
142
143// Local Variables:
144// mode: c++
145// c-file-style: "CLJ"
146// End:
static std::ostream & out0()
Return an ostream that writes from node 0.
The MemoryGrpRegion is a MemoryGrp proxy to a region of a MemoryGrp.
Definition memregion.h:46
void sync()
Synchronizes all the nodes.
void release_readwrite(void *data, distsize_t offset, size_t size)
This is called when read/write access is no longer needed.
void * obtain_readwrite(distsize_t offset, size_t size)
Only one thread can have an unreleased obtain_readwrite at a time.
void release_readonly(void *data, distsize_t offset, size_t size)
This is called when read access is no longer needed.
Ref< MemoryGrp > clone()
Returns a copy of this MemoryGrp specialization that provides an independent communication context.
MemoryGrpRegion(const Ref< MemoryGrp > &mem, size_t max_size)
same as above, except mem_start is determined automatically
void * obtain_readonly(distsize_t offset, size_t size)
This gives read access to the memory location. No locking is done.
void print(std::ostream &o=ExEnv::out0()) const
Prints out information about the object.
void * malloc_local(size_t nbytes)
Allocate data that will be accessed locally only.
void deactivate()
Deactivate is called after the memory has been used.
void catchup()
Processes outstanding requests.
MemoryGrpRegion(const Ref< MemoryGrp > &mem, size_t mem_start, size_t max_size)
MemoryGrpRegion is defined by the host MemoryGrp and position and size of the local segment within th...
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.
void free_local(void *&data)
Free data that was allocated with malloc_local, and set the pointer to 0.
void * obtain_writeonly(distsize_t offset, size_t size)
This gives write access to the memory location. No locking is done.
void set_localsize(size_t)
Set the size of locally held memory.
void release_writeonly(void *data, distsize_t offset, size_t size)
This is called when write access is no longer needed.
void * localdata()
Returns a pointer to the local data.
void activate()
Activate is called before the memory is to be used.
The MemoryGrp abstract class provides a way of accessing distributed memory in a parallel machine.
Definition memory.h:120
int size(int node)
Returns the amount of memory residing on node.
Definition memory.h:161
distsize_t offset(int node)
Returns the global offset to node's memory.
Definition memory.h:164
A template class that maintains references counts.
Definition ref.h:361
SpinCase1 other(SpinCase1 S)
given 1-spin return the other 1-spin
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.