| 1 | //
 | 
|---|
| 2 | // memmsg.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 | #ifndef _util_group_memmsg_cc
 | 
|---|
| 29 | #define _util_group_memmsg_cc
 | 
|---|
| 30 | 
 | 
|---|
| 31 | #ifdef __GNUC__
 | 
|---|
| 32 | #pragma implementation
 | 
|---|
| 33 | #endif
 | 
|---|
| 34 | 
 | 
|---|
| 35 | #include <util/group/memmsg.h>
 | 
|---|
| 36 | 
 | 
|---|
| 37 | using namespace std;
 | 
|---|
| 38 | using namespace sc;
 | 
|---|
| 39 | 
 | 
|---|
| 40 | static ClassDesc MsgMemoryGrp_cd(
 | 
|---|
| 41 |   typeid(MsgMemoryGrp),"MsgMemoryGrp",1,"public MemoryGrp",
 | 
|---|
| 42 |   0, 0, 0);
 | 
|---|
| 43 | 
 | 
|---|
| 44 | MsgMemoryGrp::MsgMemoryGrp(const Ref<MessageGrp> &msg)
 | 
|---|
| 45 | {
 | 
|---|
| 46 |   msg_ = msg;
 | 
|---|
| 47 |   n_ = msg->n();
 | 
|---|
| 48 |   me_ = msg->me();
 | 
|---|
| 49 | }
 | 
|---|
| 50 | 
 | 
|---|
| 51 | MsgMemoryGrp::MsgMemoryGrp(const Ref<KeyVal> &keyval):
 | 
|---|
| 52 |   MemoryGrp(keyval)
 | 
|---|
| 53 | {
 | 
|---|
| 54 |   Ref<MessageGrp> msg; msg << keyval->describedclassvalue("message");
 | 
|---|
| 55 |   if (msg.null()) {
 | 
|---|
| 56 |       msg = MessageGrp::get_default_messagegrp();
 | 
|---|
| 57 |     }
 | 
|---|
| 58 |   if (msg.null()) {
 | 
|---|
| 59 |       ExEnv::errn() << "MsgMemoryGrp(const Ref<KeyVal>&): couldn't find MessageGrp"
 | 
|---|
| 60 |            << endl;
 | 
|---|
| 61 |       abort();
 | 
|---|
| 62 |     }
 | 
|---|
| 63 | 
 | 
|---|
| 64 |   msg_ = msg;
 | 
|---|
| 65 |   n_ = msg->n();
 | 
|---|
| 66 |   me_ = msg->me();
 | 
|---|
| 67 | }
 | 
|---|
| 68 | 
 | 
|---|
| 69 | MsgMemoryGrp::~MsgMemoryGrp()
 | 
|---|
| 70 | {
 | 
|---|
| 71 | }
 | 
|---|
| 72 | 
 | 
|---|
| 73 | void
 | 
|---|
| 74 | MsgMemoryGrp::set_localsize(size_t localsize)
 | 
|---|
| 75 | {
 | 
|---|
| 76 |   delete[] offsets_;
 | 
|---|
| 77 | 
 | 
|---|
| 78 |   offsets_ = new distsize_t[n_ + 1];
 | 
|---|
| 79 |   int *sizes = new int[n_];
 | 
|---|
| 80 | 
 | 
|---|
| 81 |   int i;
 | 
|---|
| 82 |   for (i=0; i<n_; i++) sizes[i] = 0;
 | 
|---|
| 83 |   sizes[me_] = localsize;
 | 
|---|
| 84 | 
 | 
|---|
| 85 |   msg_->sum(sizes, n_);
 | 
|---|
| 86 | 
 | 
|---|
| 87 |   offsets_[0] = 0;
 | 
|---|
| 88 |   for (i=1; i<=n_; i++) {
 | 
|---|
| 89 |       offsets_[i] = sizes[i-1] + offsets_[i-1];
 | 
|---|
| 90 |       if (offsets_[i] < offsets_[i-1]) {
 | 
|---|
| 91 |           ExEnv::errn() << "MsgMemoryGrp::set_localsize: distsize_t cannot handle biggest size" << endl;
 | 
|---|
| 92 |           abort();
 | 
|---|
| 93 |         }
 | 
|---|
| 94 |     }
 | 
|---|
| 95 | 
 | 
|---|
| 96 |   delete[] sizes;
 | 
|---|
| 97 | }
 | 
|---|
| 98 | 
 | 
|---|
| 99 | void
 | 
|---|
| 100 | MsgMemoryGrp::sync()
 | 
|---|
| 101 | {
 | 
|---|
| 102 |   msg_->sync();
 | 
|---|
| 103 | #if 0
 | 
|---|
| 104 |   // debug code
 | 
|---|
| 105 |   for (int i=0; i<n(); i++) {
 | 
|---|
| 106 |       if (i == me()) {
 | 
|---|
| 107 |           cout << "Data on node " << i << ":" << endl;
 | 
|---|
| 108 |           for (int j=0; j<localsize()/sizeof(double); j++) {
 | 
|---|
| 109 |               double dat = ((double*)localdata())[j];
 | 
|---|
| 110 |               if (fabs(dat) > 1.e-12) {
 | 
|---|
| 111 |                   cout << " " << i << " " << offset(me()) + j << " "
 | 
|---|
| 112 |                        << setw(6)
 | 
|---|
| 113 |                        << dat << endl;
 | 
|---|
| 114 |                 }
 | 
|---|
| 115 |             }
 | 
|---|
| 116 |         }
 | 
|---|
| 117 |       cout.flush();
 | 
|---|
| 118 |       msg_->sync();
 | 
|---|
| 119 |     }
 | 
|---|
| 120 |   // end debug code
 | 
|---|
| 121 | #endif
 | 
|---|
| 122 | }
 | 
|---|
| 123 | 
 | 
|---|
| 124 | #endif
 | 
|---|
| 125 | 
 | 
|---|
| 126 | /////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 127 | 
 | 
|---|
| 128 | // Local Variables:
 | 
|---|
| 129 | // mode: c++
 | 
|---|
| 130 | // c-file-style: "CLJ"
 | 
|---|
| 131 | // End:
 | 
|---|