source: ThirdParty/mpqc_open/src/lib/util/group/memtest.cc@ 860145

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 860145 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: 11.2 KB
Line 
1//
2// memtest.cc
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#include <math.h>
29#include <util/misc/formio.h>
30#include <util/misc/bug.h>
31#include <util/group/message.h>
32#include <util/group/mstate.h>
33#include <util/group/hcube.h>
34#include <util/group/memshm.h>
35#ifdef HAVE_NX
36# include <util/group/memipgon.h>
37#endif
38
39using namespace std;
40using namespace sc;
41
42// Force linkages:
43//#ifndef __PIC__
44#ifdef HAVE_SYSV_IPC
45# include <util/group/messshm.h>
46 static ForceLink<ShmMessageGrp> fl0;
47#endif
48#ifdef HAVE_MPI
49# include <util/group/messmpi.h>
50# include <util/group/memmtmpi.h>
51 static ForceLink<MPIMessageGrp> fl2;
52 static ForceLink<MTMPIMemoryGrp> fl3;
53#endif
54//#endif
55
56#include <util/class/scexception.h>
57static const char * (sc::SCException::*force_except_link)() const
58 = &sc::SCException::description;
59
60// this is needed for debugging
61#ifdef HAVE_NX
62extern "C" {
63#include <nx.h>
64}
65#endif // HAVE_NX
66
67#ifdef HAVE_HRECV
68# define DISABLE do { masktrap(1); cout.flush(); } while(0)
69# define ENABLE do { cout.flush(); masktrap(0); } while(0)
70 extern "C" {
71 long masktrap(long state);
72 }
73#else
74# define DISABLE
75# define ENABLE
76#endif
77
78#define PRINTF(args) do { DISABLE; \
79 cout << scprintf args; \
80 cout.flush(); \
81 ENABLE; \
82 } while(0)
83
84void do_simple_tests(const Ref<MessageGrp>&,const Ref<MemoryGrp>&);
85void do_int_tests(const Ref<MessageGrp>&,const Ref<MemoryGrp>&);
86void do_double_tests(const Ref<MessageGrp>&,const Ref<MemoryGrp>&);
87void do_double2_tests(const Ref<MessageGrp>&,const Ref<MemoryGrp>&);
88
89int
90main(int argc, char**argv)
91{
92 Ref<MessageGrp> msg = MessageGrp::initial_messagegrp(argc, argv);
93
94 const char* input = SRCDIR "/memtest.in";
95 Ref<KeyVal> keyval = new ParsedKeyVal(input);
96
97 if (msg.null()) {
98 const char* keyword = "message";
99
100 if (argc >= 2) input = argv[1];
101 if (argc >= 3) keyword = argv[2];
102
103 msg << keyval->describedclassvalue(keyword);
104
105 if (msg.null()) {
106 cerr << scprintf("Couldn't initialize MessageGrp\n");
107 abort();
108 }
109 }
110
111// This causes problems for automated testing:
112// // now set up the debugger
113// Ref<Debugger> debugger;
114// debugger << keyval->describedclassvalue(":debug");
115// if (debugger.nonnull()) {
116// debugger->set_exec(argv[0]);
117// debugger->set_prefix(msg->me());
118// }
119
120 keyval = 0;
121
122 msg->sync();
123
124 MessageGrp::set_default_messagegrp(msg);
125
126 Ref<MemoryGrp> mem = MemoryGrp::initial_memorygrp(argc, argv);
127 if (mem.nonnull())
128 MemoryGrp::set_default_memorygrp(mem);
129 else
130 mem = MemoryGrp::get_default_memorygrp();
131
132 do_simple_tests(msg, mem);
133
134 do_double_tests(msg, mem);
135 do_double2_tests(msg, mem);
136
137 do_int_tests(msg, mem);
138
139 return 0;
140}
141
142void
143do_simple_tests(const Ref<MessageGrp>&msg,
144 const Ref<MemoryGrp>&mem)
145{
146 mem->set_localsize(8);
147
148 cout << scprintf("Using memory group \"%s\".\n", mem->class_name());
149
150 mem->sync();
151 mem->set_localsize(0);
152}
153
154void
155do_int_tests(const Ref<MessageGrp>&msg,
156 const Ref<MemoryGrp>&mem)
157{
158 const int intbufsize = 10;
159
160 mem->set_localsize(intbufsize*sizeof(int));
161
162 cout << scprintf("Using memory group \"%s\".\n", mem->class_name());
163
164 //sleep(1);
165 cout.flush();
166 cout << scprintf("111111111111111111111111111111111\n");
167 cout.flush();
168 //sleep(1);
169
170 mem->sync();
171
172 //sleep(1);
173 cout.flush();
174 cout << scprintf("222222222222222222222222222222222\n");
175 cout.flush();
176 //sleep(1);
177
178 //mem->deactivate();
179 //sleep(1);
180 cout.flush();
181 cout << scprintf("333333333333333333333333333333333\n");
182 cout.flush();
183 //sleep(1);
184 //mem = 0;
185 //return;
186
187 PRINTF(("creating MemoryGrpBuf\n"));
188
189 MemoryGrpBuf<int> buf(mem);
190
191 PRINTF(("%d: obtaining writelock\n", mem->me()));
192 int *data = buf.writeonly(0, intbufsize);
193 PRINTF(("%d: releasing writelock\n", mem->me()));
194 int i;
195 for (i=0; i<intbufsize; i++) data[i] = 0;
196 buf.release();
197
198 PRINTF(("%d: obtaining readlock\n", mem->me()));
199 const int *cdata = buf.readonly(0, intbufsize);
200 PRINTF(("%d: releasing readlock\n", mem->me()));
201 buf.release();
202
203// if (mem->me() == 0) {
204// cdata = buf.readonly(0, intbufsize);
205// for (i=0; i<intbufsize; i++) {
206// cout << scprintf("data[%3d] = %4d\n", i, cdata[i]);
207// }
208// buf.release();
209// }
210
211 PRINTF(("%d: syncing\n", mem->me()));
212 mem->sync();
213 PRINTF(("---------------------------------------------------------\n"));
214 mem->sync();
215 PRINTF(("%d: done syncing\n", mem->me()));
216
217 if (mem->me() == 0 || mem->me() == 1) {
218 int start[2];
219 int length[2];
220 start[0] = 0;
221 length[0] = intbufsize/2;
222 start[1] = length[0];
223 length[1] = intbufsize - length[0];
224 data = buf.readwrite(start[mem->me()], length[mem->me()]);
225 PRINTF(("%d: adding %d to [%d, %d)\n",
226 mem->me(), 10 * (mem->me()+1),
227 start[mem->me()], start[mem->me()]+length[mem->me()]));
228 for (i=0; i<buf.length(); i++) {
229 data[i] += 10 * (mem->me() + 1);
230 }
231 buf.release();
232 mem->sync();
233 PRINTF(("------------------------------------------------------\n"));
234 mem->sync();
235 data = buf.readwrite(start[1-mem->me()], length[1-mem->me()]);
236 PRINTF(("%d: adding %d to [%d, %d)\n",
237 mem->me(), 100 * (mem->me()+1),
238 start[1-mem->me()], start[1-mem->me()]+length[1-mem->me()]));
239 for (i=0; i<buf.length(); i++) {
240 data[i] += 100 * (mem->me() + 1);
241 }
242 buf.release();
243 mem->sync();
244 PRINTF(("------------------------------------------------------\n"));
245 mem->sync();
246 }
247 else {
248 mem->sync();
249 PRINTF(("------------------------------------------------------\n"));
250 mem->sync();
251 mem->sync();
252 PRINTF(("------------------------------------------------------\n"));
253 mem->sync();
254 }
255
256 if (mem->me() == 0) {
257 cdata = buf.readonly(0, intbufsize);
258 for (i=0; i<intbufsize; i++) {
259 PRINTF(("data[%3d] = %4d\n", i, cdata[i]));
260 }
261 buf.release();
262 }
263
264 PRINTF(("%d: syncing\n", mem->me()));
265 mem->sync();
266 PRINTF(("---------------------------------------------------------\n"));
267 mem->sync();
268
269 PRINTF(("%d: exiting\n", mem->me()));
270 PRINTF(("%d: syncing\n", mem->me()));
271 mem->sync();
272 PRINTF(("==========================================================\n"));
273 mem->sync();
274
275 mem->set_localsize(0);
276}
277
278void
279do_double_tests(const Ref<MessageGrp>&msg,
280 const Ref<MemoryGrp>&mem)
281{
282 PRINTF(("double tests entered\n"));
283
284 int i,j;
285
286 const int doublebufsize = 4;
287
288 mem->set_localsize(doublebufsize*sizeof(double));
289
290 cout << scprintf("Using memory group \"%s\".\n", mem->class_name());
291
292 mem->sync();
293
294 MemoryGrpBuf<double> dbuf(mem);
295
296 PRINTF(("%d: double tests mem = 0x%x\n", mem->me(), mem.pointer()));
297
298 double factor = 1.0;
299 for (i=0; i<mem->me(); i++) factor *= 10.0;
300
301 PRINTF(("%d: setting 5th digit\n", mem->me()));
302
303 double *data = dbuf.writeonly_on_node(0, doublebufsize);
304 for (i=0; i<doublebufsize; i++) {
305 data[i] = 10000.0 * (mem->me()+1) + 100000.0 * i;
306 }
307 dbuf.release();
308
309 PRINTF(("%d: 5th digit set\n", mem->me()));
310
311 double contrib[doublebufsize];
312 for (i=0; i<doublebufsize; i++) {
313 contrib[i] = (mem->me()+1) * factor;
314 }
315
316 mem->sync();
317 PRINTF(("---------------------------------------------------------\n"));
318 mem->sync();
319
320 PRINTF(("%d: starting sum reduction\n", mem->me()));
321
322 for (i=0; i<mem->n(); i++) {
323 mem->sum_reduction_on_node(contrib, mem->me(),
324 doublebufsize-mem->me(),
325 i);
326 }
327
328 PRINTF(("%d: done with sum reduction\n", mem->me()));
329
330 mem->sync();
331 PRINTF(("---------------------------------------------------------\n"));
332 mem->sync();
333
334 for (i=0; i<mem->n(); i++) {
335 mem->sync();
336 if (i==mem->me()) {
337 const double *cdata = dbuf.readonly_on_node(0, doublebufsize);
338 for (j=0; j<doublebufsize; j++) {
339 PRINTF(("%2d: %12.1f\n", i, cdata[j]));
340 }
341 dbuf.release();
342 }
343 }
344
345 mem->sync();
346 PRINTF(("---------------------------------------------------------\n"));
347 mem->sync();
348
349 for (i=0; i<mem->n(); i++) {
350 mem->sync();
351 if (i==mem->me()) {
352 const double *cdata = dbuf.readonly(0, doublebufsize*mem->n());
353 for (j=0; j<doublebufsize*mem->n(); j++) {
354 PRINTF(("%2d: data[%2d] = %12.1f\n", i, j, cdata[j]));
355 }
356 dbuf.release();
357 }
358 }
359
360 mem->sync();
361 PRINTF(("==========================================================\n"));
362 mem->sync();
363
364 mem->set_localsize(0);
365}
366
367void
368do_double2_tests(const Ref<MessageGrp>&msg,
369 const Ref<MemoryGrp>&mem)
370{
371 PRINTF(("double2 tests entered\n"));
372
373 int i,j;
374
375 const int doublebufsize = 4;
376 mem->set_localsize(doublebufsize*sizeof(double));
377 cout << scprintf("Using memory group \"%s\".\n", mem->class_name());
378
379 mem->sync();
380
381 MemoryGrpBuf<double> dbuf(mem);
382
383 double *data = dbuf.writeonly_on_node(0, doublebufsize);
384 for (i=0; i<doublebufsize; i++) {
385 data[i] = 0.0;
386 }
387 dbuf.release();
388
389 int target = (mem->me() + 1)%mem->n();
390
391 double contrib[doublebufsize];
392 for (i=0; i<doublebufsize; i++) {
393 contrib[i] = mem->me()/200.0;
394 }
395
396 mem->sync();
397 PRINTF(("---------------------------------------------------------\n"));
398 mem->sync();
399
400 PRINTF(("%d: starting sum reduction\n", mem->me()));
401
402 for (i=0; i<200; i++) {
403 mem->sum_reduction_on_node(contrib, 0,
404 doublebufsize,
405 target);
406 }
407
408 PRINTF(("%d: done with sum reduction\n", mem->me()));
409
410 mem->sync();
411 PRINTF(("---------------------------------------------------------\n"));
412 mem->sync();
413
414 for (i=0; i<mem->n(); i++) {
415 mem->sync();
416 if (i==mem->me()) {
417 const double *cdata = dbuf.readonly(0, doublebufsize*mem->n());
418 for (j=0; j<doublebufsize*mem->n(); j++) {
419 PRINTF(("%2d: data[%2d] = %12.1f\n", i, j, cdata[j]));
420 }
421 dbuf.release();
422 }
423 }
424
425 mem->sync();
426 PRINTF(("==========================================================\n"));
427 mem->sync();
428
429 mem->set_localsize(0);
430}
431
432/////////////////////////////////////////////////////////////////////////////
433
434// Local Variables:
435// mode: c++
436// c-file-style: "CLJ"
437// End:
Note: See TracBrowser for help on using the repository browser.