00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <iostream.h>
00027 #include "IpplPaws/PawsDataConnect.h"
00028 #include "Paws/PawsApplication.h"
00029 #include "Message/Message.h"
00030 #include "Utility/IpplInfo.h"
00031
00032
00033
00034 PawsApplication *PawsDataConnect::PawsApp = 0;
00035 bool PawsDataConnect::PawsReady = false;
00036 int PawsDataConnect::NumPawsConnect = 0;
00037
00038
00040
00041 PawsDataConnect::PawsDataConnect(const char *nm, int n)
00042 : DataConnect(nm, "paws", DataSource::OUTPUT, n) {
00043
00044
00045 if (PawsApp == 0) {
00046 PawsApp = new PawsApplication;
00047 PawsApp->initialize(nm, Ippl::getArgc(), Ippl::getArgv(),
00048 Ippl::myNode(), Ippl::getNodes());
00049 }
00050
00051
00052 if (PawsApp != 0)
00053 NumPawsConnect++;
00054 }
00055
00056
00058
00059 PawsDataConnect::~PawsDataConnect() {
00060
00061
00062
00063
00064 if (PawsApp != 0) {
00065
00066
00067 disconnectConnections();
00068
00069
00070 if (--NumPawsConnect == 0) {
00071
00072 barrier();
00073
00074
00075 delete PawsApp;
00076
00077 PawsApp = 0;
00078 PawsReady = false;
00079 }
00080 }
00081 }
00082
00083
00085
00086
00087
00088 void PawsDataConnect::barrier() {
00089
00090
00091 if (Ippl::getNodes() == 1) {
00092 poll();
00093 return;
00094 }
00095
00096
00097 int stag = Ippl::Comm->next_tag(COMM_REDUCE_SEND_TAG, COMM_REDUCE_CYCLE);
00098 int rtag = Ippl::Comm->next_tag(COMM_REDUCE_RECV_TAG, COMM_REDUCE_CYCLE);
00099
00100
00101 if (Ippl::myNode() != 0) {
00102
00103 Message *msg = new Message;
00104 msg->put(Ippl::myNode());
00105 Ippl::Comm->send(msg, 0, stag);
00106
00107
00108 Message *rmsg = 0;
00109 int sender = 0;
00110 while (rmsg == 0) {
00111
00112
00113 poll();
00114
00115
00116
00117 rmsg = Ippl::Comm->receive(sender, rtag);
00118 }
00119
00120
00121 rmsg->get(sender);
00122 if (sender != 0) {
00123 ERRORMSG("Bad reply node " << sender << " in PawsDataConnect::barrier");
00124 ERRORMSG(endl);
00125 }
00126 delete rmsg;
00127
00128 } else {
00129
00130
00131
00132
00133
00134
00135 int nodetotal = 0;
00136 int received = 1;
00137 while (received < Ippl::getNodes()) {
00138
00139
00140 poll();
00141
00142
00143
00144 int sender = COMM_ANY_NODE;
00145 Message *msg = Ippl::Comm->receive(sender, stag);
00146 while (msg != 0) {
00147
00148
00149 int s;
00150 msg->get(s);
00151 if (s != sender) {
00152 ERRORMSG("Bad sender's node " << s << " (should be " << sender);
00153 ERRORMSG(") in PawsDataConnect::barrier" << endl);
00154 }
00155 delete msg;
00156 msg = 0;
00157 nodetotal += s;
00158 received += 1;
00159
00160
00161 if (received < Ippl::getNodes()) {
00162 sender = COMM_ANY_NODE;
00163 msg = Ippl::Comm->receive(sender, stag);
00164 }
00165 }
00166 }
00167
00168
00169 if (nodetotal != (Ippl::getNodes() * (Ippl::getNodes()-1))/2) {
00170 ERRORMSG("Not all nodes reported properly in PawsDataConnect::barrier");
00171 ERRORMSG(" (nodetotal is " << nodetotal << ")" << endl);
00172 }
00173
00174
00175 Message *rmsg = new Message;
00176 rmsg->put(0);
00177 Ippl::Comm->broadcast_others(rmsg, rtag);
00178 }
00179 }
00180
00181
00183
00184 void PawsDataConnect::poll() {
00185 if (PawsApp != 0)
00186 PawsApp->poll();
00187 }
00188
00190
00191 void PawsDataConnect::ready() {
00192 if (PawsApp != 0)
00193 PawsApp->ready();
00194 }
00195
00196
00198
00199
00200 bool PawsDataConnect::connected() const {
00201 return (PawsApp != 0);
00202 }
00203
00204
00205
00206
00207
00208
00209