diff --git a/core/dsm/XdmfDSMBuffer.cpp b/core/dsm/XdmfDSMBuffer.cpp index 478f9bc2f05f33e5bd983026051321d28d077417..5ae525f8d11631ff3a5b5a4465d739c84300cf9a 100644 --- a/core/dsm/XdmfDSMBuffer.cpp +++ b/core/dsm/XdmfDSMBuffer.cpp @@ -837,9 +837,9 @@ XdmfDSMBuffer::ReceiveInfo() infoStatus = 1; } - int groupInfoStatus[this->Comm->GetInterSize()]; + int * groupInfoStatus = new int[this->Comm->GetInterSize()](); - MPI_Allgather(&infoStatus, 1, MPI_INT, &groupInfoStatus, 1, MPI_INT, this->Comm->GetInterComm()); + MPI_Allgather(&infoStatus, 1, MPI_INT, &(groupInfoStatus[0]), 1, MPI_INT, this->Comm->GetInterComm()); int sendCore = 0; @@ -874,7 +874,7 @@ void XdmfDSMBuffer::SendAccept(unsigned int numConnections) { for (int i = this->StartServerId; i <= this->EndServerId; ++i) { - if (i != this->Comm->GetId()){ + if (i != this->Comm->GetInterId()){ this->SendCommandHeader(XDMF_DSM_ACCEPT, i, 0, 0, XDMF_DSM_INTER_COMM); this->SendAcknowledgment(i, numConnections, XDMF_DSM_EXCHANGE_TAG, XDMF_DSM_INTER_COMM); } @@ -1053,12 +1053,12 @@ XdmfDSMBuffer::SendInfo() infoStatus = 2; } - int groupInfoStatus[this->Comm->GetInterSize()]; + int * groupInfoStatus = new int[this->Comm->GetInterSize()](); MPI_Allgather(&infoStatus, 1, MPI_INT, - &groupInfoStatus, + &(groupInfoStatus[0]), 1, MPI_INT, this->Comm->GetInterComm()); diff --git a/core/dsm/XdmfDSMCommMPI.cpp b/core/dsm/XdmfDSMCommMPI.cpp index c18ad4cecf4d9c074b318588fec014aeaa6faffd..83ffaa048489966466e1a21451b5d503b3c6bcb2 100644 --- a/core/dsm/XdmfDSMCommMPI.cpp +++ b/core/dsm/XdmfDSMCommMPI.cpp @@ -70,6 +70,7 @@ XdmfDSMCommMPI::XdmfDSMCommMPI() // This is the default file name for the config file. DsmFileName = "dsmconnect.cfg"; InterCommType = XDMF_DSM_COMM_MPI; + HasOpenedPort = false; } XdmfDSMCommMPI::~XdmfDSMCommMPI() @@ -107,7 +108,20 @@ XdmfDSMCommMPI::Accept(unsigned int numConnections) if (InterComm == MPI_COMM_NULL) { // If there is no InterComm, then accept from IntraComm and merge into InterComm MPI_Comm tempComm; - int status = MPI_Comm_accept(DsmPortName, MPI_INFO_NULL, 0, IntraComm, &tempComm); + int * portCheck = new int[GetInterSize()](); + int portStatus; + portStatus = 0; + if (HasOpenedPort) { + portStatus = 1; + } + MPI_Allgather(&portStatus, 1, MPI_INT, &(portCheck[0]), 1, MPI_INT, InterComm); + unsigned int index = 0; + for (index = 0; index < GetInterSize(); ++index) { + if (portCheck[index] == 1) { + break; + } + } + int status = MPI_Comm_accept(DsmPortName, MPI_INFO_NULL, index, IntraComm, &tempComm); if (status != MPI_SUCCESS) { try { std::string message = "Failed to accept port "; @@ -136,7 +150,20 @@ XdmfDSMCommMPI::Accept(unsigned int numConnections) else { // If there is an InterComm, accept into the InterComm and merge MPI_Comm tempComm; - int status = MPI_Comm_accept(DsmPortName, MPI_INFO_NULL, 0, InterComm, &tempComm); + int * portCheck = new int[GetInterSize()](); + int portStatus; + portStatus = 0; + if (HasOpenedPort) { + portStatus = 1; + } + MPI_Allgather(&portStatus, 1, MPI_INT, &(portCheck[0]), 1, MPI_INT, InterComm); + unsigned int index = 0; + for (index = 0; index < GetInterSize(); ++index) { + if (portCheck[index] == 1) { + break; + } + } + int status = MPI_Comm_accept(DsmPortName, MPI_INFO_NULL, index, InterComm, &tempComm); if (status != MPI_SUCCESS) { try { std::string message = "Failed to accept port "; @@ -184,6 +211,7 @@ XdmfDSMCommMPI::ClosePort() } } } + HasOpenedPort = false; } int @@ -455,6 +483,7 @@ XdmfDSMCommMPI::OpenPort() throw e; } } + HasOpenedPort = true; } MPI_Bcast(DsmPortName, MPI_MAX_PORT_NAME, MPI_CHAR, 0, IntraComm); } diff --git a/core/dsm/XdmfDSMCommMPI.hpp b/core/dsm/XdmfDSMCommMPI.hpp index d18c084bb51c0118ab6854172324139e9d18eca7..eef445a0f024c0dba3d3a867df3478ad385b4de2 100644 --- a/core/dsm/XdmfDSMCommMPI.hpp +++ b/core/dsm/XdmfDSMCommMPI.hpp @@ -1046,6 +1046,7 @@ private: int InterCommType; char DsmPortName[MPI_MAX_PORT_NAME]; std::string DsmFileName; + bool HasOpenedPort; }; #endif /* XDMFDSMCOMMMPI_HPP_ */ diff --git a/examples/Cxx/DSMLoopTest.cpp b/examples/Cxx/DSMLoopTest.cpp index 1680a0b93d3bbc56b1a4b5c597cf2cd3ac808bf6..9a169703d9dffc3a1bafb030eef0c13454c6d7a4 100644 --- a/examples/Cxx/DSMLoopTest.cpp +++ b/examples/Cxx/DSMLoopTest.cpp @@ -1,6 +1,4 @@ #include -#include -#include #include #include #include "XdmfArray.hpp"