[mpich-discuss] How to gracefully exit an MPI server process when it is waiting on MPI_Comm_accept

Joachim Protze protze at itc.rwth-aachen.de
Fri Jan 28 09:17:09 CST 2022


Hi,

since you have a separate thread for the accept, you could just set a 
flag at the main thread, open a connection from the main thread to match 
the accept. The accept thread sees the flag, immediately closes the 
connection and leaves the while loop.

  - Joachim

Am 28.01.22 um 05:54 schrieb Rupsa Chakraborty via discuss:
> 
> 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-server-process-when-it-is-waiting-on-mpi-comm-acce 
> <https://stackoverflow.com/questions/70745740/how-to-gracefully-exit-an-mpi-server-process-when-it-is-waiting-on-mpi-comm-acce>
> 
> 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(); }|
> 
> 
> 
> _______________________________________________
> discuss mailing list     discuss at mpich.org
> To manage subscription options or unsubscribe:
> https://lists.mpich.org/mailman/listinfo/discuss


-- 
Dr. rer. nat. Joachim Protze

IT Center
Group: High Performance Computing
Division: Computational Science and Engineering
RWTH Aachen University
Seffenter Weg 23
D 52074  Aachen (Germany)
Tel: +49 241 80- 24765
Fax: +49 241 80-624765
protze at itc.rwth-aachen.de
www.itc.rwth-aachen.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5327 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.mpich.org/pipermail/discuss/attachments/20220128/4a58ad7e/attachment-0001.p7s>


More information about the discuss mailing list