Re: [mpich-discuss] How to gracefully exit an MPI server process when it is waiting on MPI_Comm_accept
Hi Rupsa, With MPICH, you can set info hint "timeout" in seconds. Both MPI_Comm_accept and MPI_Comm_connect accept this info key. -- Hui Zhou ________________________________ From: Rupsa Chakraborty via discuss <[email protected]> Sent: Thursday, January 27, 2022 10:54 PM To: [email protected] <[email protected]> Cc: Rupsa Chakraborty <[email protected]> Subject: [mpich-discuss] How to gracefully exit an MPI server process when it is waiting on MPI_Comm_accept Hello, I am asking this question in this forum as I had already asked this question in stack overflow and did not receive any answer/comment: https://stackoverflow.com/questions/70745740/how-to-gracefully-exit-an-mpi-s... My concern is as follows: I have an MPI server program that calls MPI_Comm_accept, in an infinite loop, on a separate thread. The main thread spawns this thread and in parallel does some other work. At some point of time the main thread decides to exit. It closes the port using MPI_Close_port(portName), however the MPI_Comm_accept() is still waiting for connection requests. My question is: - How does the main thread exit gracefully? Is there an equivalent of socket close in MPI? I am using mpich which I can use from main thread? - Is there anyway I can set timeout to the MPI_Comm_accept call? Here is a dummy code that looks similar to my server code: // MPI Server Program void accept(std::string portName) { while (true) { MPI_Comm intercomm; MPI_Comm_accept(portName.c_str(), MPI_INFO_NULL, 0, MPI_COMM_SELF, &intercomm); // handle connection MPI_Comm_disconnect(&intercomm); } } int main() { char ch; MPI_Init(NULL, NULL); char portName[MPI_MAX_PORT_NAME]; MPI_Open_port(MPI_INFO_NULL, portName); publishName("nameServerFile.txt", "ocean", std::string(portName)); std::thread th(&accept, std::string(portName)); // do something MPI_Close_port(portName); std::cout <<"\nClosed port" << std::endl; th.join(); // main thread waits infinitely at this join // as child thread is still waiting on MPI_Comm_accept MPI_Finalize(); }
participants (1)
-
Zhou, Hui