source: ThirdParty/mpqc_open/src/lib/util/group/messint.cc@ 398fcd

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 398fcd 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.2 KB
Line 
1//
2// messint.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 <util/misc/formio.h>
29#include <util/group/message.h>
30
31using namespace std;
32using namespace sc;
33
34static ClassDesc intMessageGrp_cd(
35 typeid(intMessageGrp),"intMessageGrp",1,"public MessageGrp",
36 0, 0, 0);
37
38intMessageGrp::intMessageGrp():
39 ctl_nbit(2),
40 ctl_mask(0x3)
41{
42}
43
44intMessageGrp::intMessageGrp(const Ref<KeyVal>& keyval):
45 MessageGrp(keyval),
46 ctl_nbit(2),
47 ctl_mask(0x3)
48{
49}
50
51intMessageGrp::~intMessageGrp()
52{
53 delete[] source_seq;
54 delete[] target_seq;
55}
56
57void
58intMessageGrp::initialize(int me, int n, int nbits)
59{
60 int i;
61
62 // Initialize the arrays storing the next sequence number.
63 source_seq = new int[n];
64 target_seq = new int[n];
65 for (i=0; i<n; i++) {
66 source_seq[i] = 0;
67 target_seq[i] = 0;
68 }
69
70 // Find how many bits are needed to store the source information.
71 int tmp = 1;
72 for (i=1; tmp<n; i++) {
73 tmp = tmp<<1;
74 }
75 src_nbit = i;
76
77 // The remaining bits are for sequence information.
78 seq_nbit = nbits - ctl_nbit - src_nbit;
79 if (seq_nbit < 8) {
80 ExEnv::errn() << "intMessageGrp: not enough bits in underlying msgtype" << endl;
81 abort();
82 }
83
84 // The bits available to user defined messages overlap
85 // with the seq and the src bits.
86 typ_nbit = seq_nbit + src_nbit;
87
88 // Compute the shifts needed to construct a message type.
89 seq_shift = 0;
90 typ_shift = 0;
91 src_shift = seq_shift + seq_nbit;
92 ctl_shift = src_shift + src_nbit;
93
94 // Compute the masks for each field.
95 seq_mask = (1<<seq_nbit) - 1;
96 typ_mask = (1<<typ_nbit) - 1;
97 src_mask = (1<<src_nbit) - 1;
98
99 // Complete initialization of the base class.
100 MessageGrp::initialize(me, n);
101}
102
103int
104intMessageGrp::msgtype_typ(int msgtype)
105{
106 return msgtype>>typ_shift & typ_mask;
107}
108
109int
110intMessageGrp::typ_msgtype(int usrtype)
111{
112 return usrtype<<typ_shift | 1<<ctl_shift;
113}
114
115int
116intMessageGrp::seq_msgtype(int source, int seq)
117{
118 return source<<src_shift | seq<<seq_shift | 2<<ctl_shift;
119}
120
121void
122intMessageGrp::raw_send(int target, const void* data, int nbyte)
123{
124 int& seq = target_seq[target];
125 int msgtype = seq_msgtype(me(),seq);
126#ifdef DEBUG
127 ExEnv::outn() << scprintf("node %d sending to %d(%d) msgtype = %d\n",
128 me(),target,seq,msgtype);
129#endif
130 basic_send(target, msgtype, data, nbyte);
131 if (seq >= seq_mask) seq = 0;
132 else seq++;
133}
134
135void
136intMessageGrp::raw_recv(int sender, void* data, int nbyte)
137{
138 int& seq = source_seq[sender];
139 int msgtype = seq_msgtype(sender,seq);
140#ifdef DEBUG
141 ExEnv::outn() << scprintf("node %d receiving from %d(%d) msgtype = %d\n",
142 me(),sender,seq,msgtype);
143#endif
144 basic_recv(msgtype, data, nbyte);
145#ifdef DEBUG
146 ExEnv::outn() << scprintf("node %d received %d\n",me(),msgtype);
147#endif
148 if (seq >= seq_mask) seq = 0;
149 else seq++;
150}
151
152void
153intMessageGrp::raw_sendt(int target, int msgtype, const void* data, int nbyte)
154{
155 basic_send(target, typ_msgtype(msgtype), data, nbyte);
156}
157
158void
159intMessageGrp::raw_recvt(int type, void* data, int nbyte)
160{
161 basic_recv(typ_msgtype(type), data, nbyte);
162}
163
164int
165intMessageGrp::probet(int type)
166{
167 return basic_probe(typ_msgtype(type));
168}
169
170int
171intMessageGrp::leftover_ctl_bits()
172{
173 return 3 << ctl_shift;
174}
175
176/////////////////////////////////////////////////////////////////////////////
177
178// Local Variables:
179// mode: c++
180// c-file-style: "CLJ"
181// End:
Note: See TracBrowser for help on using the repository browser.