source: ThirdParty/mpqc_open/src/lib/chemistry/qc/mbpt/util.cc@ aae63a

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests 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_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since aae63a 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: 4.4 KB
Line 
1//
2// util.cc
3//
4// Copyright (C) 1997 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#ifdef __GNUC__
29#pragma implementation
30#endif
31
32#include <chemistry/qc/mbpt/util.h>
33
34using namespace sc;
35
36BiggestContribs::BiggestContribs(int nindex, int maxcontrib)
37{
38 maxcontrib_ = maxcontrib;
39 nindex_ = nindex;
40
41 vals_ = new double[maxcontrib_];
42
43 indices_ = new int*[maxcontrib_];
44 for (int i=0; i<maxcontrib_; i++) indices_[i] = new int[nindex_];
45
46 ncontrib_ = 0;
47}
48
49BiggestContribs::~BiggestContribs()
50{
51 delete[] vals_;
52 for (int i=0; i<maxcontrib_; i++) delete[] indices_[i];
53 delete[] indices_;
54}
55
56void
57BiggestContribs::insert(double val, int i0, int i1)
58{
59 int i[2];
60 i[0] = i0;
61 i[1] = i1;
62 insert(val,i);
63}
64
65void
66BiggestContribs::insert(double val, int i0, int i1, int i2, int i3)
67{
68 int i[4];
69 i[0] = i0;
70 i[1] = i1;
71 i[2] = i2;
72 i[3] = i3;
73 insert(val,i);
74}
75
76void
77BiggestContribs::insert(double val, int i0, int i1, int i2, int i3, int i4)
78{
79 int i[5];
80 i[0] = i0;
81 i[1] = i1;
82 i[2] = i2;
83 i[3] = i3;
84 i[4] = i4;
85 insert(val,i);
86}
87
88void
89BiggestContribs::insert(double val, const int *ii)
90{
91 if (maxcontrib_ == 0) return;
92 if (ncontrib_ == 0) {
93 vals_[0] = val;
94 memcpy(indices_[0], ii, nindex_*sizeof(int));
95 ncontrib_ = 1;
96 return;
97 }
98 int i;
99 double fabsval = (val>=0.0?val:-val);
100 int contrib = 0;
101 for (i=ncontrib_-1; i>=0; i--) {
102 double fabstmp = (vals_[i]>=0.0?vals_[i]:-vals_[i]);
103 if (fabsval > fabstmp) {
104 contrib = 1;
105 if (i < maxcontrib_-1) {
106 vals_[i+1] = vals_[i];
107 memcpy(indices_[i+1], indices_[i], nindex_*sizeof(int));
108 }
109 vals_[i] = val;
110 memcpy(indices_[i], ii, nindex_*sizeof(int));
111 }
112 else {
113 break;
114 }
115 }
116 if (ncontrib_ < maxcontrib_) {
117 if (!contrib) {
118 vals_[ncontrib_] = val;
119 memcpy(indices_[ncontrib_], ii, nindex_*sizeof(int));
120 }
121 ncontrib_++;
122 }
123}
124
125void
126BiggestContribs::combine(const Ref<MessageGrp> &grp)
127{
128 int i;
129 int n = grp->n();
130 int me = grp->me();
131 // allocate array to store the number of contribs from each node
132 int *ncontrib_each = new int[n];
133 memset(ncontrib_each, 0, n*sizeof(int));
134 ncontrib_each[me] = ncontrib_;
135 grp->sum(ncontrib_each,n);
136
137 // compute the total number of contribs and my offset for contrib data
138 int ncontrib_all = 0;
139 int contrib_offset = 0;
140 for (i=0; i<n; i++) {
141 ncontrib_all += ncontrib_each[i];
142 if (i<me) contrib_offset += ncontrib_each[i];
143 }
144
145 // allocate storage for contrib data from all nodes
146 double *vals_all = new double[ncontrib_all];
147 int **indices_all = new int*[ncontrib_all];
148 indices_all[0] = new int[ncontrib_all*nindex_];
149 for (i=1; i<ncontrib_all; i++) indices_all[i] = &indices_all[0][nindex_*i];
150 memset(vals_all, 0, sizeof(double)*ncontrib_all);
151 memset(indices_all[0], 0, sizeof(int)*ncontrib_all*nindex_);
152
153 // send contrib data from all nodes to 0
154 for (i=0; i<ncontrib_; i++) {
155 vals_all[contrib_offset+i] = vals_[i];
156 memcpy(indices_all[contrib_offset+i], indices_[i], sizeof(int)*nindex_);
157 }
158 grp->sum(vals_all, ncontrib_all);
159 grp->sum(indices_all[0], ncontrib_all*nindex_);
160
161 ncontrib_ = 0;
162 for (i=0; i<ncontrib_all; i++) {
163 insert(vals_all[i], indices_all[i]);
164 }
165
166 delete[] ncontrib_each;
167 delete[] vals_all;
168 delete[] indices_all[0];
169 delete[] indices_all;
170}
171
172/////////////////////////////////////////////////////////////////////////////
173
174// Local Variables:
175// mode: c++
176// c-file-style: "CLJ"
177// End:
Note: See TracBrowser for help on using the repository browser.