Skip to content

Guidebook: Fix recommendation for MPI Tags for Reductions

When implementing an own MPI Reductions plotter, the guidebook tells us we should write something like

  void finishRow() {
   #ifdef Parallel
   	// Question: Do we really reserve a free tag and release on each function call?
   	const int reductionTag = tarch::parallel::Node::getInstance().reserveFreeTag(
   		std::string("TimeSeriesReductions(") + filename + ")::finishRow()" );
   	if(master) {
   		double recieved[LEN];
   		for (int rank=1; rank<tarch::parallel::Node::getInstance().getNumberOfNodes(); rank++) {
   			if(!tarch::parallel::NodePool::getInstance().isIdleNode(rank)) {
   				MPI_Recv( &recieved[0], LEN, MPI_DOUBLE, rank, reductionTag, tarch::parallel::Node::getInstance().getCommunicator(), MPI_STATUS_IGNORE );
   				addValues(recieved);
   			}
   		}
   	} else {
   		for (int rank=1; rank<tarch::parallel::Node::getInstance().getNumberOfNodes(); rank++) {
   			if(!tarch::parallel::NodePool::getInstance().isIdleNode(rank)) {
   				MPI_Send( &data[0], LEN, MPI_DOUBLE, tarch::parallel::Node::getGlobalMasterRank(), reductionTag, tarch::parallel::Node::getInstance().getCommunicator());
   			}
   		}
   	}

   	tarch::parallel::Node::getInstance().releaseTag(reductionTag);
   #endif
   if(master) {
   	TimeSeriesReductions::finishRow();
   	writeRow();
   }
   }

However I assume this is not that good, looking at the output:

mpi-reservefreetags

First question: Does every plotter need it's own tag? In principal only if they would be called in parallel, isn't it?

In any case, I think the tags should'nt be created so frequently, isn't it? Instead, only once on startup time?

This should be fixed in the guidebook and my code :D