source: ThirdParty/mpqc_open/src/lib/util/group/memrdma.cc@ 7516f6

Action_Thermostats Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Exclude_Hydrogens_annealWithBondGraph Fix_Verbose_Codepatterns ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool PythonUI_with_named_parameters Recreated_GuiChecks StoppableMakroAction TremoloParser_IncreasedPrecision
Last change on this file since 7516f6 was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 6.6 KB
Line 
1//
2// memrdma.cc
3// Based on memamsg.cc
4//
5// Copyright (C) 1996 Limit Point Systems, Inc.
6//
7// Author: Curtis Janssen <cljanss@limitpt.com>
8// Maintainer: LPS
9//
10// This file is part of the SC Toolkit.
11//
12// The SC Toolkit is free software; you can redistribute it and/or modify
13// it under the terms of the GNU Library General Public License as published by
14// the Free Software Foundation; either version 2, or (at your option)
15// any later version.
16//
17// The SC Toolkit is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU Library General Public License for more details.
21//
22// You should have received a copy of the GNU Library General Public License
23// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
24// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25//
26// The U.S. Government is granted a limited license as per AL 91-7.
27//
28
29#ifndef _util_group_memrdma_cc
30#define _util_group_memrdma_cc
31
32#ifdef __GNUC__
33#pragma implementation
34#endif
35
36#include <util/class/scexception.h>
37#include <util/misc/formio.h>
38#include <util/group/pool.h>
39#include <util/group/memrdma.h>
40#include <util/group/memiter.h>
41#include <stdexcept>
42
43using namespace std;
44using namespace sc;
45
46#ifdef HAVE_HRECV
47# define DISABLE do { masktrap(1); ExEnv::outn().flush(); } while(0)
48# define ENABLE do { ExEnv::outn().flush(); masktrap(0); } while(0)
49 extern "C" {
50 long masktrap(long state);
51 }
52#else
53# define DISABLE ExEnv::outn().flush()
54# define ENABLE ExEnv::outn().flush()
55#endif
56
57#define PRINTF(args) do { DISABLE; \
58 ExEnv::outn() << scprintf args ; \
59 ExEnv::outn().flush(); \
60 ENABLE; \
61 } while(0)
62
63#undef PRINTF
64#define PRINTF(args)
65
66///////////////////////////////////////////////////////////////////////
67// Members for RDMAMemoryGrp
68
69static ClassDesc RDMAMemoryGrp_cd(
70 typeid(RDMAMemoryGrp),"RDMAMemoryGrp",1,"public MsgMemoryGrp",
71 0, 0, 0);
72
73RDMAMemoryGrp::RDMAMemoryGrp(const Ref<MessageGrp>& msg):
74 MsgMemoryGrp(msg)
75{
76 data_ = 0;
77 default_pool_size_ = 1000000;
78}
79
80RDMAMemoryGrp::RDMAMemoryGrp(const Ref<KeyVal>& keyval):
81 MsgMemoryGrp(keyval)
82{
83 data_ = 0;
84 default_pool_size_ = 1000000;
85}
86
87void*
88RDMAMemoryGrp::malloc_region(size_t nbyte)
89{
90 void *data = 0;
91 for (int i=0; data==0 && i<pools_.size(); i++) {
92 data = pools_[i]->allocate(nbyte);
93 }
94 if (data == 0) {
95 if (default_pool_size_ < nbyte) default_pool_size_ = nbyte * 2;
96 else if (pools_.size() > 4) default_pool_size_ *= 2;
97 void *pooldata = malloc_local(default_pool_size_);
98 Pool *pool = new(pooldata) Pool(default_pool_size_);
99 pools_.push_back(pool);
100 data = pool->allocate(nbyte);
101 }
102 return data;
103}
104
105void
106RDMAMemoryGrp::free_region(void*data)
107{
108 char *cdata = reinterpret_cast<char*>(data);
109 for (int i=0; i<pools_.size(); i++) {
110 char *pstart = reinterpret_cast<char*>(pools_[i]);
111 if (cdata > pstart && cdata < &pstart[pools_[i]->size()]) {
112 pools_[i]->release(data);
113 return;
114 }
115 }
116 throw ProgrammingError("could not find data to release in a Pool",
117 __FILE__, __LINE__, this->class_desc());
118}
119
120void
121RDMAMemoryGrp::set_localsize(size_t localsize)
122{
123 for (int i=0; i<pools_.size(); i++) {
124 free_local(pools_[i]);
125 }
126 pools_.resize(0);
127
128 MsgMemoryGrp::set_localsize(localsize);
129}
130
131void *
132RDMAMemoryGrp::localdata()
133{
134 return data_;
135}
136
137RDMAMemoryGrp::~RDMAMemoryGrp()
138{
139 deactivate();
140 delete[] data_;
141}
142
143void *
144RDMAMemoryGrp::obtain_writeonly(distsize_t offset, int size)
145{
146 void *data = malloc_region(size);
147 return data;
148}
149
150void *
151RDMAMemoryGrp::obtain_readwrite(distsize_t offset, int size)
152{
153 PRINTF(("RDMAMemoryGrp::obtain_readwrite entered\n"));
154 void *data = malloc_region(size);
155 MemoryIter i(data, offsets_, n());
156 for (i.begin(offset, size); i.ready(); i.next()) {
157 PRINTF(("RDMAMemoryGrp::obtain_readwrite: node = %d, "
158 "int offset = %d, int size = %d\n",
159 i.node(), i.offset()/sizeof(int), i.size()/sizeof(int)));
160 retrieve_data(i.data(), i.node(), i.offset(), i.size(), 1);
161 }
162 PRINTF(("RDMAMemoryGrp::obtain_readwrite exiting\n"));
163 return data;
164}
165
166void *
167RDMAMemoryGrp::obtain_readonly(distsize_t offset, int size)
168{
169 void *data = malloc_region(size);
170 PRINTF(("%d: RDMAMemoryGrp::obtain_readonly:"
171 "overall: offset = %d size = %d\n",
172 me(), offset, size));
173 MemoryIter i(data, offsets_, n());
174 for (i.begin(offset, size); i.ready(); i.next()) {
175 PRINTF(("%d: RDMAMemoryGrp::obtain_readonly:working on:"
176 "node = %d offset = %d size = %d\n",
177 me(), i.node(), i.offset(), i.size()));
178 PRINTF(("RDMAMemoryGrp::obtain_readonly: node = %d, "
179 "int offset = %d, int size = %d\n",
180 i.node(), i.offset()/sizeof(int), i.size()/sizeof(int)));
181 retrieve_data(i.data(), i.node(), i.offset(), i.size(), 0);
182 }
183 return data;
184}
185
186void
187RDMAMemoryGrp::sum_reduction(double *data, distsize_t doffset, int dsize)
188{
189 distsize_t offset = doffset * sizeof(double);
190 int size = dsize * sizeof(double);
191 MemoryIter i(data, offsets_, n());
192 for (i.begin(offset, size); i.ready(); i.next()) {
193 sum_data((double*)i.data(), i.node(), i.offset(), i.size());
194 }
195}
196
197void
198RDMAMemoryGrp::sum_reduction_on_node(double *data, size_t doffset,
199 int dlength, int node)
200{
201 if (node == -1) node = me();
202
203 sum_data(data, node, sizeof(double)*doffset, sizeof(double)*dlength);
204}
205
206void
207RDMAMemoryGrp::release_readonly(void *data, distsize_t offset, int size)
208{
209 free_region(data);
210}
211
212void
213RDMAMemoryGrp::release_writeonly(void *data, distsize_t offset, int size)
214{
215 MemoryIter i(data, offsets_, n());
216 for (i.begin(offset, size); i.ready(); i.next()) {
217 PRINTF(("RDMAMemoryGrp::release_write: node = %d, "
218 "int offset = %d, int size = %d\n",
219 i.node(), i.offset()/sizeof(int), i.size()/sizeof(int)));
220 replace_data(i.data(), i.node(), i.offset(), i.size(), 0);
221 }
222 free_region(data);
223}
224
225void
226RDMAMemoryGrp::release_readwrite(void *data, distsize_t offset, int size)
227{
228 MemoryIter i(data, offsets_, n());
229 for (i.begin(offset, size); i.ready(); i.next()) {
230 replace_data(i.data(), i.node(), i.offset(), i.size(), 1);
231 }
232 free_region(data);
233}
234
235void
236RDMAMemoryGrp::print(ostream &o) const
237{
238 MemoryGrp::print(o);
239}
240
241#endif
242
243/////////////////////////////////////////////////////////////////////////////
244
245// Local Variables:
246// mode: c++
247// c-file-style: "CLJ"
248// End:
Note: See TracBrowser for help on using the repository browser.