<div dir="ltr">Hi Hui, Joachim,<div><br></div><div>Thanks for the information. </div><div>I am not able to find in the internet a clear example as to how to populate MPI_Info and use it with MPI_Comm_accept. I tried to do the following, but this is giving errors as shown below.<br>Could you provide a small example to set up a timeout with MPI_Comm_accept? Do I need to populate port info too with MPI_Info?<br><br>            MPI_Init(NULL, NULL);  <br>            char portName[MPI_MAX_PORT_NAME];    <br>            MPI_Open_port(MPI_INFO_NULL, portName);    <br><br>            MPI_Info info;<br>            MPI_Info_create( &info );<br>            MPI_Info_set(info, "timeout", "2");<br><br>            MPI_Comm intercomm;<br>            MPI_Comm_accept(portName, info, 0, MPI_COMM_SELF, &intercomm);  </div><div> <br></div><div>Error:<br>$ ./server <br>Waiting to accept.... <br>Abort(671693606) on node 0 (rank 0 in comm 0): Fatal error in internal_Comm_accept: Invalid port, error stack:<br>internal_Comm_accept(102)....: MPI_Comm_accept(port_name=tag#0$connentry#020098ADAC1785B70000000000000000$, info=0x9c000002, 0, MPI_COMM_SELF, newcomm=0x7f79b17dbcb8) failed<br>MPID_Comm_accept(442)........: <br>dynamic_intercomm_create(400): <br>peer_intercomm_create(334)...: <br>(unknown)(): Invalid port<br></div><div><br></div><div>Regards,</div><div>Rupsa</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 28, 2022 at 8:47 PM Joachim Protze <<a href="mailto:protze@itc.rwth-aachen.de">protze@itc.rwth-aachen.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
since you have a separate thread for the accept, you could just set a <br>
flag at the main thread, open a connection from the main thread to match <br>
the accept. The accept thread sees the flag, immediately closes the <br>
connection and leaves the while loop.<br>
<br>
  - Joachim<br>
<br>
Am 28.01.22 um 05:54 schrieb Rupsa Chakraborty via discuss:<br>
> <br>
> Hello,<br>
> <br>
> I am asking this question in this forum as I had already asked this <br>
> question in stack overflow and did not receive any answer/comment:<br>
> <a href="https://stackoverflow.com/questions/70745740/how-to-gracefully-exit-an-mpi-server-process-when-it-is-waiting-on-mpi-comm-acce" rel="noreferrer" target="_blank">https://stackoverflow.com/questions/70745740/how-to-gracefully-exit-an-mpi-server-process-when-it-is-waiting-on-mpi-comm-acce</a> <br>
> <<a href="https://stackoverflow.com/questions/70745740/how-to-gracefully-exit-an-mpi-server-process-when-it-is-waiting-on-mpi-comm-acce" rel="noreferrer" target="_blank">https://stackoverflow.com/questions/70745740/how-to-gracefully-exit-an-mpi-server-process-when-it-is-waiting-on-mpi-comm-acce</a>><br>
> <br>
> My concern is as follows:<br>
> I have an MPI server program that calls MPI_Comm_accept, in an infinite <br>
> loop, on a separate thread. The main thread spawns this thread and in <br>
> parallel does some other work. At some point of time the main thread <br>
> decides to exit. It closes the port using MPI_Close_port(portName), <br>
> however the MPI_Comm_accept() is still waiting for connection requests.<br>
> <br>
> <br>
> My question is:<br>
> - How does the main thread exit gracefully? Is there an equivalent of <br>
> socket close in MPI? I am using mpich which I can use from main thread?<br>
> <br>
> - Is there anyway I can set timeout to the MPI_Comm_accept call?<br>
> <br>
> Here is a dummy code that looks similar to my server code:<br>
> <br>
> |// MPI Server Program void accept(std::string portName) { while (true) <br>
> { MPI_Comm intercomm; MPI_Comm_accept(portName.c_str(), MPI_INFO_NULL, <br>
> 0, MPI_COMM_SELF, &intercomm); // handle connection <br>
> MPI_Comm_disconnect(&intercomm); } } int main() { char ch; <br>
> MPI_Init(NULL, NULL); char portName[MPI_MAX_PORT_NAME]; <br>
> MPI_Open_port(MPI_INFO_NULL, portName); <br>
> publishName("nameServerFile.txt", "ocean", std::string(portName)); <br>
> std::thread th(&accept, std::string(portName)); // do something <br>
> MPI_Close_port(portName); std::cout <<"\nClosed port" << std::endl; <br>
> th.join(); // main thread waits infinitely at this join // as child <br>
> thread is still waiting on MPI_Comm_accept MPI_Finalize(); }|<br>
> <br>
> <br>
> <br>
> _______________________________________________<br>
> discuss mailing list     <a href="mailto:discuss@mpich.org" target="_blank">discuss@mpich.org</a><br>
> To manage subscription options or unsubscribe:<br>
> <a href="https://lists.mpich.org/mailman/listinfo/discuss" rel="noreferrer" target="_blank">https://lists.mpich.org/mailman/listinfo/discuss</a><br>
<br>
<br>
-- <br>
Dr. rer. nat. Joachim Protze<br>
<br>
IT Center<br>
Group: High Performance Computing<br>
Division: Computational Science and Engineering<br>
RWTH Aachen University<br>
Seffenter Weg 23<br>
D 52074  Aachen (Germany)<br>
Tel: +49 241 80- 24765<br>
Fax: +49 241 80-624765<br>
<a href="mailto:protze@itc.rwth-aachen.de" target="_blank">protze@itc.rwth-aachen.de</a><br>
<a href="http://www.itc.rwth-aachen.de" rel="noreferrer" target="_blank">www.itc.rwth-aachen.de</a><br>
</blockquote></div>