~ubuntu-branches/ubuntu/oneiric/mpqc/oneiric

« back to all changes in this revision

Viewing changes to src/lib/util/group/pregtime.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2005-11-27 11:41:49 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051127114149-zgz9r3gk50w8ww2q
Tags: 2.3.0-1
* New upstream release.
* debian/rules (SONAME): Activate awk snippet for automatic so-name
  detection again, resulting in a bump to `7' and making a `c2a' for
  the C++ allocator change unnecessary; closes: #339232.
* debian/patches/00list (08_gcc-4.0_fixes): Removed, no longer needed.
* debian/rules (test): Remove workarounds, do not abort build if tests
  fail.
* debian/ref: Removed.
* debian/control.in (libsc): Added Conflict against libsc6c2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
{
65
65
}
66
66
 
 
67
static void
 
68
send_string(const Ref<MessageGrp>& msg, int node, const char *s)
 
69
{
 
70
  int l = strlen(s);
 
71
  msg->send(node, l);
 
72
  msg->send(node, s, l);
 
73
}
 
74
 
 
75
static char *
 
76
recv_string(const Ref<MessageGrp>& msg, int node)
 
77
{
 
78
  int l;
 
79
  msg->recv(node, l);
 
80
  char *s = new char[l+1];
 
81
  s[l] = '\0';
 
82
  msg->recv(node, s, l);
 
83
  return s;
 
84
}
 
85
 
 
86
void
 
87
ParallelRegionTimer::send_subregions(int node, const TimedRegion *r) const
 
88
{
 
89
  TimedRegion *subr = r->subregions();
 
90
 
 
91
  // rewind to the beginning
 
92
  if (subr) { while (subr->prev()) subr = subr->prev(); }
 
93
 
 
94
  while (subr) {
 
95
      msg_->send(node, 1);
 
96
      send_string(msg_, node, subr->name());
 
97
      send_subregions(node, subr);
 
98
      subr = subr->next();
 
99
    };
 
100
 
 
101
  msg_->send(node, 0);
 
102
}
 
103
 
 
104
void
 
105
ParallelRegionTimer::recv_subregions(int node, TimedRegion *r) const
 
106
{
 
107
  int has_subregions;
 
108
  msg_->recv(node, has_subregions);
 
109
  while (has_subregions) {
 
110
      char *name = recv_string(msg_, node);
 
111
      TimedRegion *region = r->findinsubregion(name);
 
112
      delete[] name;
 
113
      recv_subregions(node, region);
 
114
      msg_->recv(node, has_subregions);
 
115
    }
 
116
}
 
117
 
 
118
void
 
119
ParallelRegionTimer::all_reduce_regions() const
 
120
{
 
121
  Ref<MachineTopology> topology = msg_->topology();
 
122
 
 
123
  // accumulate all the regions onto node zero
 
124
  Ref<GlobalMsgIter> i_reduce(topology->global_msg_iter(msg_, 0));
 
125
  for (i_reduce->backwards(); !i_reduce->done(); i_reduce->next()) {
 
126
      if (i_reduce->send()) {
 
127
          send_subregions(i_reduce->sendto(), top_);
 
128
        }
 
129
      if (i_reduce->recv()) {
 
130
          recv_subregions(i_reduce->recvfrom(), top_);
 
131
        }
 
132
    }
 
133
 
 
134
  // broadcast the regions to all the nodes
 
135
  Ref<GlobalMsgIter> i_bcast(topology->global_msg_iter(msg_, 0));
 
136
  for (i_bcast->forwards(); !i_bcast->done(); i_bcast->next()) {
 
137
      if (i_bcast->send()) {
 
138
          send_subregions(i_bcast->sendto(), top_);
 
139
        }
 
140
      if (i_bcast->recv()) {
 
141
          recv_subregions(i_bcast->recvfrom(), top_);
 
142
        }
 
143
    }
 
144
}
 
145
 
67
146
void
68
147
ParallelRegionTimer::print(ostream &o) const
69
148
{
76
155
 
77
156
  update_top();
78
157
 
 
158
  // make sure all the nodes have the same regions
 
159
  all_reduce_regions();
 
160
 
79
161
  int n = nregion();
80
162
 
81
 
  int minn = n;
82
 
  int maxn = n;
83
 
  msg_->max(maxn);
84
 
  msg_->min(minn);
85
 
 
86
 
  if (maxn != minn) {
87
 
      ExEnv::err0()
88
 
           << "ParallelRegionTimer::print: differing number of regions"
89
 
           << endl;
90
 
      abort();
91
 
    }
92
 
 
93
163
  double *cpu_time = 0;
94
164
  double *wall_time = 0;
95
165
  double *flops = 0;