// // messtest.cc // // Copyright (C) 1996 Limit Point Systems, Inc. // // Author: Curtis Janssen // Maintainer: LPS // // This file is part of the SC Toolkit. // // The SC Toolkit is free software; you can redistribute it and/or modify // it under the terms of the GNU Library General Public License as published by // the Free Software Foundation; either version 2, or (at your option) // any later version. // // The SC Toolkit is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Library General Public License for more details. // // You should have received a copy of the GNU Library General Public License // along with the SC Toolkit; see the file COPYING.LIB. If not, write to // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. // // The U.S. Government is granted a limited license as per AL 91-7. // #include #include #include #include #include #include #include #include using namespace std; using namespace sc; // Force linkages: //#ifndef __PIC__ #ifndef PUMAGON # include static ForceLink fl0; #endif # ifdef HAVE_MPI # include static ForceLink fl2; # endif //#endif class A: virtual public SavableState { private: int ia; int n; int* array; double d; public: A(int size); A(const Ref&); A(StateIn&); ~A(); void save_data_state(StateOut&); inline int& a() { return ia; }; virtual void print (ostream&s = cout) { s << "A::a = " << a() << '\n'; s << "A::array = {"; for (int i=0; i&keyval): ia(keyval->intvalue("a")), n(keyval->intvalue("n")), d(-1.24) { array = new int[n]; for (int i=0; i, create); void test(const Ref&, int source, int target); void test_hcube(int nproc, int root, int fwd); int main(int argc, char**argv) { Ref grp = MessageGrp::initial_messagegrp(argc, argv); Ref debugger; if (grp.null()) { const char* input = SRCDIR "/messtest.in"; const char* keyword = "message"; if (argc >= 2) input = argv[1]; if (argc >= 3) keyword = argv[2]; Ref keyval = new ParsedKeyVal(input); grp << keyval->describedclassvalue(keyword); debugger << keyval->describedclassvalue(":debug"); if (grp.null()) { cerr << scprintf("Couldn't initialize MessageGrp\n"); abort(); } } if (debugger.nonnull()) { debugger->set_exec(argv[0]); debugger->set_prefix(grp->me()); } Debugger::set_default_debugger(debugger); grp->sync(); if (grp->n() > 1) { BcastState bc(grp,1); bc.bcast(debugger); bc.flush(); } grp->sync(); if (debugger.nonnull()) { debugger->set_exec(argv[0]); debugger->set_prefix(grp->me()); debugger->traceback(); } grp->sync(); if (0 && grp->me() == 0) { test_hcube(3, 0, 1); test_hcube(39, 0, 1); test_hcube(16, 0, 1); test_hcube(17, 4, 1); test_hcube(17, 4, 0); test_hcube(1, 0, 0); } grp->sync(); if (grp->n() >= 3) { test(grp, 2, 1); } else { test(grp, 0, 0); } int testsum = 1; grp->sum(&testsum,1); if (testsum != grp->n()) { cerr << scprintf("WARNING: sum wrong\n"); } double testdsum = 1.0; grp->sum(&testdsum,1); cout << scprintf("on %d testdsum = %4.1f\n", grp->me(), testdsum); grp->sync(); grp = 0; return 0; } void test_hcube(int nproc, int root, int fwd) { int i, j; Ref *gmi = new Ref[nproc]; for (i=0; iforwards(); } else { gmi[j]->backwards(); } } while (!gmi[0]->done()) { cout << scprintf("------ step %d of %d ------\n", iter, gmi[0]->n()); for (j=0; jsend()) { if (0 <= gmi[j]->sendto() && gmi[j]->sendto() < nproc) { if (gmi[gmi[j]->sendto()]->recvfrom() == j) { cout << scprintf(" %d -> %d\n", j, gmi[j]->sendto()); } else { cout << scprintf(" %d -> (%d)\n", j, gmi[j]->sendto()); } } else { cout << scprintf(" %d -> %d?\n", j, gmi[j]->sendto()); } } else if (gmi[j]->recv()) { if (0 <= gmi[j]->recvfrom() && gmi[j]->recvfrom() < nproc) { if (gmi[gmi[j]->recvfrom()]->sendto() == j) { // to be printed by sender } else { cout << scprintf(" (%d) -> %d\n", gmi[j]->recvfrom(), j); } } else { cout << scprintf(" %d? -> %d\n", gmi[j]->recvfrom(), j); } } } for (j=0; jnext(); iter++; } cout.flush(); } void test(const Ref& grp, int source, int target) { Ref a,b; const int nca = 1000000; char ca[nca]; if (grp->me() == source) { StateSend so(grp); //so.set_buffer_size(5); so.target(target); a = new A(10); SavableState::save_state(a,so); so.flush(); grp->send(target, ca, nca); if (source != target) grp->recv(target, ca, nca); } if (grp->me() == target) { StateRecv si(grp); //si.set_buffer_size(5); si.source(source); b << SavableState::restore_state(si); if (source != target) grp->send(source, ca, nca); grp->recv(source, ca, nca); } if (grp->me() == target) { cout << "target:" << endl; b->print(); } grp->sync(); if (grp->me() == source) { cout << "source:" << endl; a->print(); } /////////////////////////////////////////////////// // Test broadcast if (source != target) { grp->sync(); b = 0; if (grp->me() == source) { BcastStateSend so(grp); SavableState::save_state(a,so); } else { BcastStateRecv si(grp,source); b << SavableState::restore_state(si); } if (grp->me() == target) { cout << "bcast target:" << endl; b->print(); } } } ///////////////////////////////////////////////////////////////////////////// // Local Variables: // mode: c++ // c-file-style: "CLJ" // End: