Skip to content

Commit e204da5

Browse files
committed
Merge PR #5 from @memmett to torbjoernk/PFASST
* torbjoernk/pr/5/head: pfasst: Add tags to status send/recv. Fix malformed MPI send/recv. Signed-off-by: Torbjörn Klatt <[email protected]>
2 parents d58f075 + 4748da2 commit e204da5

File tree

5 files changed

+35
-24
lines changed

5 files changed

+35
-24
lines changed

include/pfasst/controller/pfasst.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ namespace pfasst
8080
* @param[in] level_iter level iterator providing information to compute the communication tag
8181
*/
8282
virtual int tag(LevelIter level_iter);
83+
virtual int stag(LevelIter level_iter);
8384

8485
/**
8586
* Post current status and values to next processor.

include/pfasst/interfaces.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ namespace pfasst
143143
//! @}
144144

145145
//! @{
146-
virtual void post() = 0;
147-
virtual void send() = 0;
148-
virtual void recv() = 0;
146+
virtual void post(int tag) = 0;
147+
virtual void send(int tag) = 0;
148+
virtual void recv(int tag) = 0;
149149
//! @}
150150
};
151151

@@ -222,7 +222,7 @@ namespace pfasst
222222
* Perform one SDC sweep/iteration.
223223
*
224224
* Compute a correction and update solution values.
225-
* Note that this function can assume that valid function values exist from a previous
225+
* Note that this function can assume that valid function values exist from a previous
226226
* pfasst::ISweeper::sweep() or pfasst::ISweeper::predict().
227227
*/
228228
virtual void sweep() = 0;
@@ -314,7 +314,7 @@ namespace pfasst
314314
*
315315
* @param[in,out] dst sweeper to interpolate onto (i.e. fine level)
316316
* @param[in] src sweeper to interpolate from (i.e. coarse level)
317-
* @param[in] interp_initial `true` if a delta for the initial condtion should also be
317+
* @param[in] interp_initial `true` if a delta for the initial condtion should also be
318318
* computed (PFASST)
319319
*/
320320
virtual void interpolate(shared_ptr<ISweeper<time>> dst,

include/pfasst/mpi_communicator.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ namespace pfasst
105105
virtual void clear() override;
106106
virtual void set_converged(bool converged) override;
107107
virtual bool get_converged(int rank) override;
108-
virtual void post();
109-
virtual void send();
110-
virtual void recv();
108+
virtual void post(int tag) override;
109+
virtual void send(int tag) override;
110+
virtual void recv(int tag) override;
111111
};
112112
} // ::pfasst::mpi
113113
} // ::pfasst

src/pfasst/controller/pfasst_impl.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,12 @@ namespace pfasst
9797
perform_sweeps(l.level);
9898

9999
if (l == this->finest() && fine->converged()) {
100-
this->comm->status->set_converged(true);
100+
bool previous_converged = this->comm->status->previous_is_iterating();
101+
this->comm->status->set_converged(!previous_converged);
101102
}
102103

103104
fine->send(comm, tag(l), false);
104-
105105
trns->restrict(crse, fine, true);
106-
107106
trns->fas(this->get_time_step(), crse, fine);
108107
crse->save();
109108

@@ -136,10 +135,10 @@ namespace pfasst
136135
if (this->comm->status->previous_is_iterating()) {
137136
crse->recv(comm, tag(level_iter), true);
138137
}
139-
this->comm->status->recv();
138+
this->comm->status->recv(stag(level_iter));
140139
this->perform_sweeps(level_iter.level);
140+
this->comm->status->send(stag(level_iter));
141141
crse->send(comm, tag(level_iter), true);
142-
this->comm->status->send();
143142
return level_iter + 1;
144143
}
145144

@@ -205,13 +204,19 @@ namespace pfasst
205204
* @internals
206205
* A simple formula is used with current level index \\( L \\) (provided by @p level_iter) and
207206
* current iteration number \\( I \\):
208-
* \\[ L * 10000 + I + 10 \\]
207+
* \\[ (L+1) * 10000 + I \\]
209208
* @endinternals
210209
*/
211210
template<typename time>
212211
int PFASST<time>::tag(LevelIter level_iter)
213212
{
214-
return level_iter.level * 10000 + this->get_iteration() + 10;
213+
return (level_iter.level+1) * 10000 + this->get_iteration();
214+
}
215+
216+
template<typename time>
217+
int PFASST<time>::stag(LevelIter level_iter)
218+
{
219+
return level_iter.level * 1000 + this->get_iteration();
215220
}
216221

217222
/**
@@ -222,7 +227,7 @@ namespace pfasst
222227
void PFASST<time>::post()
223228
{
224229
if (this->comm->status->previous_is_iterating()) {
225-
this->comm->status->post();
230+
this->comm->status->post(0);
226231
for (auto l = this->coarsest() + 1; l <= this->finest(); ++l) {
227232
l.current()->post(comm, tag(l));
228233
}

src/pfasst/mpi_communicator_impl.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ namespace pfasst
9696
return this->converged.at(rank);
9797
}
9898

99-
void MPIStatus::post()
99+
void MPIStatus::post(int tag)
100100
{
101101
// noop: send/recv for status info is blocking
102+
UNUSED(tag);
102103
}
103104

104-
void MPIStatus::send()
105+
void MPIStatus::send(int tag)
105106
{
106107
// don't send forward if: single processor run, or we're the last processor
107108
if (mpi->size() == 1) { return; }
@@ -110,13 +111,15 @@ namespace pfasst
110111
int iconverged = converged.at(mpi->rank()) ? IStatus::CONVERGED : IStatus::NOT_CONVERGED;
111112
int dest_rank = (mpi->rank() + 1) % mpi->size();
112113

113-
CLOG(DEBUG, "Controller") << "sending converged status to rank " << dest_rank << " with tag '1': " << ((bool)iconverged == IStatus::CONVERGED);
114-
int err = MPI_Send(&iconverged, sizeof(int), MPI_INT, dest_rank, 1, mpi->comm);
114+
CLOG(DEBUG, "Controller") << "sending converged status to rank " << dest_rank
115+
<< " with tag " << tag << ": "
116+
<< boolalpha << ((bool)iconverged == IStatus::CONVERGED);
117+
int err = MPI_Send(&iconverged, 1, MPI_INT, dest_rank, tag, mpi->comm);
115118
check_mpi_error(err);
116119
CLOG(DEBUG, "Controller") << "sent converged status";
117120
}
118121

119-
void MPIStatus::recv()
122+
void MPIStatus::recv(int tag)
120123
{
121124
// don't recv if: single processor run, or we're the first processor
122125
if (mpi->size() == 1) { return; }
@@ -130,10 +133,12 @@ namespace pfasst
130133
MPI_Status stat = MPI_Status_factory();
131134
int iconverged = IStatus::NOT_CONVERGED;
132135
int src_rank = (mpi->rank() - 1) % mpi->size();
133-
CLOG(DEBUG, "Controller") << "recieving converged status from rank " << src_rank << " with tag '1'";
134-
int err = MPI_Recv(&iconverged, sizeof(iconverged), MPI_INT, src_rank, 1, mpi->comm, &stat);
136+
CLOG(DEBUG, "Controller") << "receiving converged status from rank " << src_rank << " with tag '1'";
137+
int err = MPI_Recv(&iconverged, 1, MPI_INT, src_rank, tag, mpi->comm, &stat);
135138
check_mpi_error(err);
136-
CLOG(DEBUG, "Controller") << "recieved converged status from rank " << src_rank << " with tag '1': " << ((bool)iconverged == IStatus::CONVERGED);
139+
CLOG(DEBUG, "Controller") << "received converged status from rank " << src_rank
140+
<< " with tag "<< tag << ": "
141+
<< boolalpha << ((bool)iconverged == IStatus::CONVERGED);
137142

138143
converged.at(mpi->rank() - 1) = (iconverged == IStatus::CONVERGED) ? true : false;
139144
}

0 commit comments

Comments
 (0)