source: ThirdParty/mpqc_open/src/lib/util/group/messproc.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.3 KB
Line 
1//
2// messproc.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 sc;
32
33static ClassDesc ProcMessageGrp_cd(
34 typeid(ProcMessageGrp),"ProcMessageGrp",1,"public MessageGrp",
35 0, create<ProcMessageGrp>, 0);
36
37ProcMessageGrp::ProcMessageGrp(const Ref<KeyVal>& keyval):
38 MessageGrp(keyval)
39{
40 sync_messages=0;
41 type_messages=0;
42 initialize(0,1);
43}
44
45ProcMessageGrp::ProcMessageGrp()
46{
47 sync_messages=0;
48 type_messages=0;
49 initialize(0,1);
50}
51
52ProcMessageGrp::~ProcMessageGrp()
53{
54}
55
56Ref<MessageGrp> ProcMessageGrp::clone(void)
57{
58 Ref<MessageGrp> pmg = new ProcMessageGrp;
59 return pmg;
60}
61
62void ProcMessageGrp::sendit(message_t *& messages, int dest, int msgtype, const void* buf,
63 int bytes)
64{
65 message_t *msg;
66 message_t *I;
67
68 if (dest != 0) {
69 ExEnv::errn() << scprintf("messproc.cc:sendit: can only send to 0\n");
70 abort();
71 }
72
73 msg = (message_t *) malloc(sizeof(message_t));
74 if (msg) msg->buf = (char *) malloc(bytes);
75 if (!msg || !msg->buf) {
76 ExEnv::errn() << scprintf("messproc.cc:sendit: allocation failed\n");
77 abort();
78 }
79
80 // Put msg at the end of the linked list, because of some bad
81 // assumptions made by the mpscf program and libraries.
82 msg->p = 0;
83 if (!messages) {
84 messages = msg;
85 }
86 else {
87 for (I=messages; I->p != 0; I=I->p);
88 I->p = msg;
89 }
90
91 memcpy(msg->buf,buf,bytes);
92 msg->type = msgtype;
93 msg->size = bytes;
94}
95
96void ProcMessageGrp::recvit(message_t *& messages, int source, int type, void* buf,
97 int bytes, int& last_size, int& last_type)
98{
99 message_t *i;
100 message_t *last;
101
102 last = 0;
103 for (i=messages; i!=0; i = i->p) {
104 if (i->type == type || type == -1) {
105 if (i->size > bytes) {
106 ExEnv::errn() << scprintf(
107 "messproc.cc:recvit: message buffer isn't big enough\n");
108 abort();
109 }
110 memcpy(buf,i->buf,i->size);
111
112 // Remove the message from the list.
113 if (last) {
114 last->p = i->p;
115 }
116 else {
117 messages = messages->p;
118 }
119 free(i->buf);
120 free(i);
121
122 return;
123 }
124 last = i;
125 }
126
127 ExEnv::errn() << scprintf(
128 "messproc.cc:recvit: tried to receive something that isn't there\n");
129 ExEnv::errn() << scprintf("messproc:recvit: tried %d bytes of type %d, ",bytes,type);
130 abort();
131}
132
133void
134ProcMessageGrp::raw_send(int target, const void* data, int nbyte)
135{
136 sendit(sync_messages, target, -1, data, nbyte);
137}
138
139void
140ProcMessageGrp::raw_sendt(int target, int type, const void* data, int nbyte)
141{
142 sendit(type_messages, target, type, data, nbyte);
143}
144
145void
146ProcMessageGrp::raw_recv(int sender, void* data, int nbyte)
147{
148 int last_size, last_type;
149 recvit(sync_messages, sender, -1, data, nbyte, last_size, last_type);
150}
151
152void
153ProcMessageGrp::raw_recvt(int type, void* data, int nbyte)
154{
155 int last_size, last_type;
156 recvit(type_messages, -1, type, data, nbyte, last_size, last_type);
157}
158
159void
160ProcMessageGrp::raw_bcast(void* data, int nbyte, int from)
161{
162}
163
164int
165ProcMessageGrp::probet(int type)
166{
167 message_t *i;
168
169 for (i=type_messages; i!=0; i = i->p) {
170 if (i->type == type || type == -1) {
171 return 1;
172 }
173 }
174
175 return 0;
176}
177
178void
179ProcMessageGrp::sync()
180{
181}
182
183/////////////////////////////////////////////////////////////////////////////
184
185// Local Variables:
186// mode: c++
187// c-file-style: "CLJ"
188// End:
Note: See TracBrowser for help on using the repository browser.