source: ThirdParty/mpqc_open/src/lib/util/group/memmsg.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: 3.0 KB
Line 
1//
2// memmsg.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#ifndef _util_group_memmsg_cc
29#define _util_group_memmsg_cc
30
31#ifdef __GNUC__
32#pragma implementation
33#endif
34
35#include <util/group/memmsg.h>
36
37using namespace std;
38using namespace sc;
39
40static ClassDesc MsgMemoryGrp_cd(
41 typeid(MsgMemoryGrp),"MsgMemoryGrp",1,"public MemoryGrp",
42 0, 0, 0);
43
44MsgMemoryGrp::MsgMemoryGrp(const Ref<MessageGrp> &msg)
45{
46 msg_ = msg;
47 n_ = msg->n();
48 me_ = msg->me();
49}
50
51MsgMemoryGrp::MsgMemoryGrp(const Ref<KeyVal> &keyval):
52 MemoryGrp(keyval)
53{
54 Ref<MessageGrp> msg; msg << keyval->describedclassvalue("message");
55 if (msg.null()) {
56 msg = MessageGrp::get_default_messagegrp();
57 }
58 if (msg.null()) {
59 ExEnv::errn() << "MsgMemoryGrp(const Ref<KeyVal>&): couldn't find MessageGrp"
60 << endl;
61 abort();
62 }
63
64 msg_ = msg;
65 n_ = msg->n();
66 me_ = msg->me();
67}
68
69MsgMemoryGrp::~MsgMemoryGrp()
70{
71}
72
73void
74MsgMemoryGrp::set_localsize(size_t localsize)
75{
76 delete[] offsets_;
77
78 offsets_ = new distsize_t[n_ + 1];
79 int *sizes = new int[n_];
80
81 int i;
82 for (i=0; i<n_; i++) sizes[i] = 0;
83 sizes[me_] = localsize;
84
85 msg_->sum(sizes, n_);
86
87 offsets_[0] = 0;
88 for (i=1; i<=n_; i++) {
89 offsets_[i] = sizes[i-1] + offsets_[i-1];
90 if (offsets_[i] < offsets_[i-1]) {
91 ExEnv::errn() << "MsgMemoryGrp::set_localsize: distsize_t cannot handle biggest size" << endl;
92 abort();
93 }
94 }
95
96 delete[] sizes;
97}
98
99void
100MsgMemoryGrp::sync()
101{
102 msg_->sync();
103#if 0
104 // debug code
105 for (int i=0; i<n(); i++) {
106 if (i == me()) {
107 cout << "Data on node " << i << ":" << endl;
108 for (int j=0; j<localsize()/sizeof(double); j++) {
109 double dat = ((double*)localdata())[j];
110 if (fabs(dat) > 1.e-12) {
111 cout << " " << i << " " << offset(me()) + j << " "
112 << setw(6)
113 << dat << endl;
114 }
115 }
116 }
117 cout.flush();
118 msg_->sync();
119 }
120 // end debug code
121#endif
122}
123
124#endif
125
126/////////////////////////////////////////////////////////////////////////////
127
128// Local Variables:
129// mode: c++
130// c-file-style: "CLJ"
131// End:
Note: See TracBrowser for help on using the repository browser.