Thanks!<br><br><div class="gmail_quote">On Fri, Oct 28, 2011 at 11:17 AM, Darius Buntinas <span dir="ltr"><<a href="mailto:buntinas@mcs.anl.gov">buntinas@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Jon,<br>
<br>
I had to pull out my copy of the standard for this one :-). The standard says (Section 10.5.4 on pg 330) that MPI_Finalize is collective over "connected" processes. By the definition of "connected" (in the same section), the master and worker processes in your application are still connected, so the worker process might wait until the master process calls MPI_Finalize (in the case of MPICH, it will wait if the two processes have ever communicated). You can use MPI_Comm_disconnect to disconnect the master and worker before the worker calls MPI_Finalize.<br>
<br>
I added an MPI_Comm_disconnect on line 37 and line 80 of your program and it looks like it works as you intend.<br>
<br>
-d<br>
<div><div></div><div class="h5"><br>
<br>
On Oct 28, 2011, at 11:18 AM, Jonathan Bishop wrote:<br>
<br>
> I am using MPI_Comm_spawn to dynamically run workers. However, when the workers exit they get hung up on MPI_Finalize. Here is a short program which shows the issue...<br>
><br>
> It responds to several commands...<br>
><br>
> Do<br>
><br>
> start<br>
> stop<br>
><br>
> and then check how many processes are running - it should be 1, not 2.<br>
><br>
> I am using MPICH2 1.4.1-p1.<br>
><br>
> Thanks,<br>
><br>
> Jon<br>
><br>
> #include <sys/types.h><br>
> #include <unistd.h><br>
> #include <iostream><br>
> #include "mpi.h"<br>
><br>
> using namespace std;<br>
><br>
><br>
> main(int argc, char **argv)<br>
> {<br>
> MPI_Init(&argc, &argv);<br>
> MPI_Comm parent;<br>
> MPI_Comm_get_parent(&parent);<br>
><br>
> // Master<br>
> if (parent == MPI_COMM_NULL) {<br>
> cout << getpid() << endl;<br>
> MPI_Comm intercom = MPI_COMM_NULL;<br>
> while (1) {<br>
> cout << "Enter: ";<br>
> string s;<br>
> cin >> s;<br>
> if (s == "start") {<br>
> if (intercom != MPI_COMM_NULL) {<br>
> cout << "already started" << endl;<br>
> continue;<br>
> }<br>
> MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 1, MPI_INFO_NULL, 0, MPI_COMM_SELF, &intercom, MPI_ERRCODES_IGNORE);<br>
> continue;<br>
> }<br>
> if (s == "stop") {<br>
> if (intercom == MPI_COMM_NULL) {<br>
> cout << "worker not running" << endl;<br>
> continue;<br>
> }<br>
> MPI_Send(const_cast<char*>(s.c_str()), s.size(), MPI_CHAR, 0, 0, intercom);<br>
> intercom = MPI_COMM_NULL;<br>
> // MPI_Finalize(); // This will allow the workers to die, but then I can not restart them.<br>
> continue;<br>
> }<br>
> if (s == "exit") {<br>
> if (intercom != MPI_COMM_NULL) {<br>
> cout << "need to stop before exit" << endl;<br>
> continue;<br>
> }<br>
> break;<br>
> }<br>
> if (intercom == MPI_COMM_NULL) {<br>
> cout << "need to start" << endl;<br>
> continue;<br>
> }<br>
> MPI_Send(const_cast<char*>(s.c_str()), s.size(), MPI_CHAR, 0, 0, intercom);<br>
> char buf[1000];<br>
> MPI_Status status;<br>
> MPI_Recv(buf, 1000, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, intercom, &status);<br>
> int count;<br>
> MPI_Get_count(&status, MPI_CHAR, &count);<br>
> buf[count] = 0;<br>
> string t = buf;<br>
> cout << "worker returned " << t << endl;<br>
> }<br>
> }<br>
><br>
> // Worker<br>
> if (parent != MPI_COMM_NULL) {<br>
> while (1) {<br>
> char buf[1000];<br>
> MPI_Status status;<br>
> MPI_Recv(buf, 1000, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, parent, &status);<br>
> int count;<br>
> MPI_Get_count(&status, MPI_CHAR, &count);<br>
> buf[count] = 0;<br>
> string s = buf;<br>
> if (s == "stop") {<br>
> cout << "worker stopping" << endl;<br>
> break;<br>
> }<br>
> MPI_Send(const_cast<char*>(s.c_str()), s.size(), MPI_CHAR, 0, 0, parent);<br>
> }<br>
> }<br>
><br>
> MPI_Finalize();<br>
> }<br>
><br>
</div></div>> _______________________________________________<br>
> mpich-discuss mailing list <a href="mailto:mpich-discuss@mcs.anl.gov">mpich-discuss@mcs.anl.gov</a><br>
> To manage subscription options or unsubscribe:<br>
> <a href="https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss" target="_blank">https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss</a><br>
<br>
_______________________________________________<br>
mpich-discuss mailing list <a href="mailto:mpich-discuss@mcs.anl.gov">mpich-discuss@mcs.anl.gov</a><br>
To manage subscription options or unsubscribe:<br>
<a href="https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss" target="_blank">https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss</a><br>
</blockquote></div><br>