<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>[mpich-discuss] Running one MPI program from another</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16825" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=363365613-24042009>Hi,</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=363365613-24042009> Great... Let us know if you need any
help.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=363365613-24042009></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=363365613-24042009>Regards,</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=363365613-24042009>Jayesh</SPAN></FONT></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Rod Cook [mailto:rod@cookies.demon.co.uk]
<BR><B>Sent:</B> Friday, April 24, 2009 8:50 AM<BR><B>To:</B> Jayesh
Krishna<BR><B>Cc:</B> mpich-discuss@mcs.anl.gov<BR><B>Subject:</B> Re:
[mpich-discuss] Running one MPI program from another<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV><FONT face=Arial size=2>Jayesh</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>The environment block was the problem. I've
included a modified version of the test program that works. I've also made the
mod in my actual application and works OK .</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Thanks for your help, much
appreciated.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Rod</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>#include "stdafx.h"<BR>#include
"Userenv.h"<BR>#include <afx.h><BR>#include "mpi.h"</FONT></DIV>
<DIV><FONT face=Arial size=2>int run_program( char * program
)<BR>{<BR> STARTUPINFO si;<BR> PROCESS_INFORMATION
pi;<BR> LPVOID env = NULL;<BR>
CreateEnvironmentBlock(&env, NULL, FALSE);<BR> ZeroMemory(
&si, sizeof(si) );<BR> si.cb = sizeof(si);<BR>
ZeroMemory( &pi, sizeof(pi) );<BR> if( !CreateProcess(
NULL, // No module name (use command
line)<BR>
program, // Command
line<BR>
NULL, // Process
handle not inheritable<BR>
NULL, // Thread
handle not inheritable<BR>
FALSE, // Set handle
inheritance to FALSE<BR>
CREATE_UNICODE_ENVIRONMENT,
// Created environment block contains unicode<BR>
env, // Use
created environment block<BR>
NULL, // Use
parent's starting directory <BR>
&si, //
Pointer to STARTUPINFO structure<BR> &pi
) // Pointer to
PROCESS_INFORMATION structure<BR> )
<BR> {<BR> return -1;<BR>
}<BR> WaitForSingleObject( pi.hProcess, INFINITE );<BR>
CloseHandle( pi.hProcess );<BR> CloseHandle( pi.hThread
);<BR> return 0;<BR>}<BR>int main(int argc, char*
argv[])<BR>{<BR> MPI_Init(NULL,NULL);<BR>
run_program("prog");<BR> MPI_Finalize();<BR> return
0;<BR>}<BR></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=jayesh@mcs.anl.gov href="mailto:jayesh@mcs.anl.gov">Jayesh
Krishna</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=rod@cookies.demon.co.uk
href="mailto:rod@cookies.demon.co.uk">'Rod Cook'</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Cc:</B> <A title=mpich-discuss@mcs.anl.gov
href="mailto:mpich-discuss@mcs.anl.gov">mpich-discuss@mcs.anl.gov</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Thursday, April 23, 2009 3:53
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> RE: [mpich-discuss] Running one
MPI program from another</DIV>
<DIV><BR></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=503564814-23042009>Hi,</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=503564814-23042009> Since you are passing in a NULL value for the
environment block the new process created is inheriting the environment from
the parent (since this environment includes the runtime env for an MPI process
it should not be shared among two MPI processes). This could be your
problem. Can you try passing a dummy environment block instead of NULL in
CreateProcess() ?</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=503564814-23042009></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=503564814-23042009>Regards,</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=503564814-23042009>Jayesh</SPAN></FONT></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Rod Cook
[mailto:rod@cookies.demon.co.uk] <BR><B>Sent:</B> Thursday, April 23, 2009
3:42 AM<BR><B>To:</B> Jayesh Krishna<BR><B>Cc:</B>
mpich-discuss@mcs.anl.gov<BR><B>Subject:</B> Re: [mpich-discuss] Running one
MPI program from another<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV><FONT face=Arial size=2>Jayesh</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Using "mpiexec -n 1 prog" doesn't
work.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Cheers</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Rod</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=jayesh@mcs.anl.gov href="mailto:jayesh@mcs.anl.gov">Jayesh
Krishna</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=rod@cookies.demon.co.uk
href="mailto:rod@cookies.demon.co.uk">'Rod Cook'</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Cc:</B> <A title=mpich-discuss@mcs.anl.gov
href="mailto:mpich-discuss@mcs.anl.gov">mpich-discuss@mcs.anl.gov</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Wednesday, April 22, 2009 8:38
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [mpich-discuss] Running one
MPI program from another</DIV>
<DIV><BR></DIV><!-- Converted from text/plain format -->
<P><FONT size=2>Hi,<BR> Try launching "mpiexec -n 1 prog" instead of
"prog" with CreateProcess(). Let us know if it works for
you.<BR><BR>Regards,<BR>Jayesh<BR><BR>--------------------------------------------------------------------------------<BR>From:
<A
href="mailto:mpich-discuss-bounces@mcs.anl.gov">mpich-discuss-bounces@mcs.anl.gov</A>
[<A
href="mailto:mpich-discuss-bounces@mcs.anl.gov">mailto:mpich-discuss-bounces@mcs.anl.gov</A>]
On Behalf Of Rod Cook<BR>Sent: Wednesday, April 22, 2009 10:12 AM<BR>To:
Jayesh Krishna<BR>Cc: <A
href="mailto:mpich-discuss@mcs.anl.gov">mpich-discuss@mcs.anl.gov</A><BR>Subject:
Re: [mpich-discuss] Running one MPI program from
another<BR><BR><BR>Jayesh,<BR><BR>I can get my example code to work using
MPI_Comm_spawn but it doesn't work for my actual application. The problem
with using MPI_Comm_spawn is that I don't know how to tell that the spawned
program has finished -- this is why I used CreateProcess because it is
possible to wait for the program to terminate. The spawned program could be
a non MPI executable or a standalone MPI executable which can't communicate
with the program calling MPI_Comm_spawn.<BR><BR>Cheers,<BR><BR>Rod<BR>-----
Original Message -----<BR>From: Jayesh Krishna<BR>To: 'Rod Cook'<BR>Cc:
mpich-discuss@mcs.anl.gov<BR>Sent: Wednesday, April 22, 2009 3:40
PM<BR>Subject: RE: [mpich-discuss] Running one MPI program from
another<BR><BR><BR>Hi,<BR> Did you try MPI_Comm_spawn()
?<BR><BR>Regards,<BR>Jayesh<BR><BR><BR><BR>--------------------------------------------------------------------------------<BR>From:
mpich-discuss-bounces@mcs.anl.gov [<A
href="mailto:mpich-discuss-bounces@mcs.anl.gov">mailto:mpich-discuss-bounces@mcs.anl.gov</A>]
On Behalf Of Rod Cook<BR>Sent: Wednesday, April 22, 2009 7:50 AM<BR>To:
mpich-discuss@mcs.anl.gov<BR>Subject: [mpich-discuss] Running one MPI
program from another<BR><BR><BR>Hi,<BR><BR>I am trying to run an MPI program
(prog) from another MPI program (test) using CreateProcess under Windows
XP. I am using MPICH2 v1.08.<BR><BR>Source for test<BR>#include
"stdafx.h"<BR>#include <afx.h><BR>#include "mpi.h"<BR>int run_program(
char * program )<BR>{<BR> STARTUPINFO si;<BR>
PROCESS_INFORMATION pi;<BR> ZeroMemory( &si, sizeof(si)
);<BR> si.cb = sizeof(si);<BR> ZeroMemory( &pi,
sizeof(pi) );<BR> if( !CreateProcess( NULL, program, NULL, NULL,
FALSE, 0, NULL, NULL, &si, &pi ) )<BR>
{<BR> return -1;<BR>
}<BR> WaitForSingleObject( pi.hProcess, INFINITE
);<BR> CloseHandle( pi.hProcess );<BR> CloseHandle(
pi.hThread );<BR> return 0;<BR>}<BR>int main(int argc, char*
argv[])<BR>{<BR> MPI_Init(NULL,NULL);<BR>
run_program("prog");<BR> MPI_Finalize();<BR> return
0;<BR>}<BR><BR>Source for prog<BR>#include "stdafx.h"<BR>#include
"mpi.h"<BR>int main(int argc, char* argv[])<BR>{<BR> MPI_Init(
NULL, NULL );<BR> MPI_Finalize();<BR> return
0;<BR>}<BR><BR>I get the following error when I run test:<BR><BR>>mpiexec
-n 1 test<BR>MPIDU_Sock_post_connect failed.<BR>[0] PMI_ConnectToHost
failed: unable to post a connect to Yellowtail
yellowtail<BR>
:2057, error: Unknown error class, error
stack:<BR>MPIDU_Sock_post_connect(1228): unable to connect to Yellowtail
yellowtail<BR> on port 2057, exhausted all endpoints (errno
-1)<BR>MPIDU_Sock_post_connect(1275): unable to connect
to
on port 2057,<BR> No connection could be made because the target
machine actively refused it. (er<BR>rno
10061)<BR>MPIDU_Sock_post_connect(1275): unable to connect to yellowtail on
port 2057, No<BR>connection could be made because the target machine
actively refused it. (errno<BR>10061)<BR>MPIDU_Sock_post_connect(1275):
unable to connect to Yellowtail on port 2057, No<BR>connection could be made
because the target machine actively refused it.
(errno<BR>10061)<BR>uPMI_ConnectToHost returning PMI_FAIL<BR>[0] PMI_Init
failed.<BR>Fatal error in MPI_Init: Other MPI error, error
stack:<BR>MPIR_Init_thread(294): Initialization
failed<BR>MPID_Init(83)........: channel initialization
failed<BR>MPID_Init(334).......: PMI_Init returned -1<BR>><BR><BR>In my
actual application prog is either a standalone MPI program which I can't
change or a non MPI program (in which case test works) .<BR><BR><BR>I'd be
gratefull for any help.<BR><BR><BR>Thanks<BR><BR>Rod Cook<BR> </FONT>
</P></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>