Commit cb20a57e authored by Sonja Happ's avatar Sonja Happ

use MPI_Ibcast in forward and backward sweeps, ignore statuses

parent 6ce9e074
......@@ -145,9 +145,11 @@ void Model::do_backward_sweep() {
if (!contains_slack && world_size > 1) {
// if rank does not contain slack it starts an async. broadcast here
IO->start_time_measurement(IO->tm_bcast_backward_sweep);
IO->log_info("Backward sweep: issuing Irecv");
MPI_Irecv(&value, 1, MPI_INT, agent_rank_relation[SLACK_ID-1],
BACKWARD_COMPLETION_TAG, filled_ranks, &backward_req[rank]);
IO->log_info("Backward sweep: issuing receive");
//MPI_Irecv(&value, 1, MPI_INT, agent_rank_relation[SLACK_ID-1],
// BACKWARD_COMPLETION_TAG, filled_ranks, &backward_req[rank]);
MPI_Ibcast(&value, 1, MPI_INT, agent_rank_relation[SLACK_ID-1], filled_ranks,&backward_req[rank]);
IO->stop_time_measurement(IO->tm_bcast_backward_sweep);
}
......@@ -179,22 +181,26 @@ void Model::do_backward_sweep() {
if ((slack->get_next_action_expected() == FORWARD_SWEEP)) {
backward_sweep_finished = true;
value = 1;
if(world_size > 1){
IO->log_info("Backward sweep finished, sending info");
// inform all other processes about convergence
for(int i=0; i<=highest_filled_rank; i++){
if (i != rank) {
value = 1;
MPI_Isend(&value, 1, MPI_INT, i,
BACKWARD_COMPLETION_TAG, filled_ranks, &backward_req[i]);
}
}
for(int i=0; i<=highest_filled_rank; i++){
if (i != rank) {
MPI_Wait(&backward_req[i], &status[i]);
}
}
MPI_Ibcast(&value, 1, MPI_INT, agent_rank_relation[SLACK_ID-1], filled_ranks,&backward_req[rank]);
//for(int i=0; i<=highest_filled_rank; i++){
// if (i != rank) {
//MPI_Isend(&value, 1, MPI_INT, i,
// BACKWARD_COMPLETION_TAG, filled_ranks, &backward_req[i]);
// }
//}
MPI_Wait(&backward_req[rank], MPI_STATUS_IGNORE);
//for(int i=0; i<=highest_filled_rank; i++){
// if (i != rank) {
// MPI_Wait(&backward_req[i], &status[i]);
// }
//}
}
}
} // check finished
......@@ -213,7 +219,7 @@ void Model::do_backward_sweep() {
// check status of asynchronous MPI Broadcast operation as stop criterion of while loop
IO->stop_time_measurement(IO->tm_backward_sweep);
IO->start_time_measurement(IO->tm_bcast_backward_sweep);
MPI_Test(&backward_req[rank], &flag, &status[rank]);
MPI_Test(&backward_req[rank], &flag, MPI_STATUS_IGNORE);
IO->log_info("BW MPI-Test has returned: " + std::to_string(flag));
if (flag){
backward_sweep_finished = true;
......@@ -250,8 +256,9 @@ void Model::do_forward_sweep() {
if (!contains_slack && world_size > 1) {
IO->start_time_measurement(IO->tm_bcast_forward_sweep);
// if rank does not contain slack it starts an async. broadcast here
MPI_Irecv(&value, 1, MPI_INT, agent_rank_relation[SLACK_ID-1],
FORWARD_COMPLETION_TAG, filled_ranks, &forward_req[rank]);
//MPI_Irecv(&value, 1, MPI_INT, agent_rank_relation[SLACK_ID-1],
// FORWARD_COMPLETION_TAG, filled_ranks, &forward_req[rank]);
MPI_Ibcast(&value, 1, MPI_INT, agent_rank_relation[SLACK_ID-1], filled_ranks,&forward_req[rank]);
IO->stop_time_measurement(IO->tm_bcast_forward_sweep);
}
......@@ -297,31 +304,33 @@ void Model::do_forward_sweep() {
Agent * slack = context.getAgent(repast::AgentId(SLACK_ID,rank,TYPE_SLACK_INT, rank));
if((slack->get_next_action_expected() == BACKWARD_SWEEP)){
forward_sweep_finished = true;
value = 1;
if(world_size > 1){
IO->log_info("Forward sweep finished, sending info");
// inform all other processes about convergence
for(int i=0; i<=highest_filled_rank; i++){
if (i != rank) {
value = 1;
MPI_Isend(&value, 1, MPI_INT, i,
FORWARD_COMPLETION_TAG, filled_ranks, &forward_req[i]);
}
}
for(int i=0; i<=highest_filled_rank; i++){
if (i != rank) {
IO->log_info("Waiting for Irecv of rank " + std::to_string(i));
MPI_Wait(&forward_req[i], &status[i]);
}
}
MPI_Ibcast(&value, 1, MPI_INT, agent_rank_relation[SLACK_ID-1], filled_ranks,&forward_req[rank]);
// for(int i=0; i<=highest_filled_rank; i++){
// if (i != rank) {
// value = 1;
// MPI_Isend(&value, 1, MPI_INT, i,
// FORWARD_COMPLETION_TAG, filled_ranks, &forward_req[i]);
// }
// }
MPI_Wait(&forward_req[rank], MPI_STATUS_IGNORE);
// for(int i=0; i<=highest_filled_rank; i++){
// if (i != rank) {
// IO->log_info("Waiting for Irecv of rank " + std::to_string(i));
// MPI_Wait(&forward_req[i], &status[i]);
// }
// }
}
}
} // finished check
// This barrier is required to make sure that all processes
// know about the finished state before entering the next loop iteration
MPI_Barrier(filled_ranks);
IO->stop_time_measurement(IO->tm_bcast_forward_sweep);
......@@ -336,7 +345,7 @@ void Model::do_forward_sweep() {
// check status of asynchronous MPI Broadcast operation as stop criterion of while loop
IO->stop_time_measurement(IO->tm_forward_sweep);
IO->start_time_measurement(IO->tm_bcast_forward_sweep);
MPI_Test(&forward_req[rank], &flag, &status[rank]);
MPI_Test(&forward_req[rank], &flag, MPI_STATUS_IGNORE);
IO->log_info("FW MPI-Test has returned: " + std::to_string(flag));
if(flag){
forward_sweep_finished = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment