Created
July 24, 2013 01:40
-
-
Save dstuebe/6067520 to your computer and use it in GitHub Desktop.
Running OpenMPI process from Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mpi4py import MPI | |
comm = MPI.COMM_WORLD | |
size = comm.Get_size() | |
rank = comm.Get_rank() | |
if rank == 0: | |
data = {'key1' : [7, 2.72, 2+3j], | |
'key2' : ( 'abc', 'xyz')} | |
else: | |
data = None | |
data = comm.bcast(data, root=0) | |
print 'Hello from %s of %s: data: %s' % (rank, size, data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
if __name__ == '__main__': | |
print os.linesep.join('='.join((key, value)) for key, value in os.environ.items()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Creating Process | |
==== Process Builder Commands === | |
C:\Python27\Lib\site-packages\mpi4py\bin\mpiexec.exe | |
-n | |
1 | |
C:\Python27\python.exe | |
env.py | |
==== Process Builder Environment === | |
USERPROFILE = C:\Users\dstuebe.ASA | |
SSH_AGENT_PID = 5116 | |
JAVA_HOME = C:\Program Files\Java\jdk1.7.0_06 | |
SystemDrive = C: | |
Path = C:\Users\dstuebe.ASA\Documents\HDF_Group\HDF5\1.8.11\x32\bin;C:\Program Files (x86)\Intel\Composer XE 2011 SP1.325\redist\intel64\mkl;C:\Program Files (x86)\Intel\Composer XE 2011 SP1\redist\ia32\tbb\vc10;C:\Program Files (x86)\Intel\Composer XE 2011 SP1\redist\intel64\tbb\vc10;C:\Program Files (x86)\Intel\Composer XE 2011 SP1\redist\intel64\ipp;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Intel\Composer XE 2011 SP1\redist\intel64\mkl;C:\Program Files (x86)\Intel\Composer XE 2011 SP1\redist\ia32\mkl;C:\Program Files (x86)\Common Files\Microsoft Shared\VSA\10.0\VsaEnv;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32\compiler;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\apache-ant-1.8.4\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\TortoiseGit\bin;C:\Program Files\Java\jdk1.7.0_06\bin;C:\Users\dstuebe.ASA\Documents\simple_jna\fortran\lib;C:\Program Files (x86)\CMake 2.8\bin | |
PROCESSOR_REVISION = 2505 | |
VSSHELL2010INSTALLDIR = C:\Program Files (x86)\Microsoft Visual Studio 10.0\ | |
USERDOMAIN = ASA | |
ALLUSERSPROFILE = C:\ProgramData | |
F_IA32_REDIST12 = C:\Program Files (x86)\Common Files\Intel\Shared Libraries\ | |
IFORT_COMPILER12 = C:\Program Files (x86)\Intel\Composer XE 2011 SP1.325\ | |
SESSIONNAME = Console | |
TMP = C:\Users\dstuebe.ASA\AppData\Local\Temp | |
CommonProgramFiles = C:\Program Files\Common Files | |
=:: = ::\ | |
INSPECTOR_XE_2011_DIR = C:\Program Files (x86)\Intel\Inspector XE 2011\ | |
LOGONSERVER = \\ASAMSG | |
PROCESSOR_LEVEL = 6 | |
LOCALAPPDATA = C:\Users\dstuebe.ASA\AppData\Local | |
COMPUTERNAME = SCI053_VM003 | |
SystemRoot = C:\Windows | |
USERNAME = DStuebe | |
F_EM64T_REDIST12 = C:\Program Files (x86)\Common Files\Intel\Shared Libraries\ | |
C_EM64T_REDIST12 = C:\Program Files (x86)\Common Files\Intel\Shared Libraries\ | |
APPDATA = C:\Users\dstuebe.ASA\AppData\Roaming | |
ProgramData = C:\ProgramData | |
USERDNSDOMAIN = ASA.LOCAL | |
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC | |
windows_tracing_logfile = C:\BVTBin\Tests\installpackage\csilogfile.log | |
ProgramFiles(x86) = C:\Program Files (x86) | |
TEMP = C:\Users\dstuebe.ASA\AppData\Local\Temp | |
windows_tracing_flags = 3 | |
ProgramFiles = C:\Program Files | |
VTUNE_AMPLIFIER_XE_2011_DIR = C:\Program Files (x86)\Intel\VTune Amplifier XE 2011\ | |
HOMEDRIVE = C: | |
SSH_AUTH_SOCK = /tmp/ssh-kyboNC4240/agent.4240 | |
ProgramW6432 = C:\Program Files | |
PROCESSOR_IDENTIFIER = Intel64 Family 6 Model 37 Stepping 5, GenuineIntel | |
PROCESSOR_ARCHITECTURE = AMD64 | |
FP_NO_HOST_CHECK = NO | |
OS = Windows_NT | |
HOMEPATH = \Users\dstuebe.ASA | |
CommonProgramW6432 = C:\Program Files\Common Files | |
INTEL_LICENSE_FILE = C:\Program Files (x86)\Common Files\Intel\Licenses | |
ANT_HOME = C:\Program Files\apache-ant-1.8.4 | |
ICPP_COMPILER12 = C:\Program Files (x86)\Intel\Composer XE 2011 SP1\ | |
windir = C:\Windows | |
NUMBER_OF_PROCESSORS = 2 | |
PUBLIC = C:\Users\Public | |
PSModulePath = C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ | |
CommonProgramFiles(x86) = C:\Program Files (x86)\Common Files | |
ComSpec = C:\Windows\system32\cmd.exe | |
==== Process Output === | |
E: [SCI053_VM003:02928] ..\..\openmpi-1.6.4\opal\event\event.c: ompi_evesel->dispatch() failed. | |
I: TMP=C:\Users\dstuebe.ASA\AppData\Local\Temp | |
I: | |
I: COMPUTERNAME=SCI053_VM003 | |
I: | |
I: OMPI_MCA_ORTE_HNP_URI=4182966272.0;tcp://192.168.1.11:50570 | |
I: | |
I: INTEL_LICENSE_FILE=C:\Program Files (x86)\Common Files\Intel\Licenses | |
I: | |
I: PROCESSOR_ARCHITECTURE=AMD64 | |
I: | |
I: VSSHELL2010INSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 10.0\ | |
I: | |
I: OMPI_MCA_ORTE_ESS_NUM_PROCS=1 | |
I: | |
I: PSMODULEPATH=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ | |
I: | |
I: OMPI_MCA_ESS=env | |
I: | |
I: COMMONPROGRAMFILES=C:\Program Files\Common Files | |
I: | |
I: PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 37 Stepping 5, GenuineIntel | |
I: | |
I: PROGRAMFILES=C:\Program Files | |
I: | |
I: PROCESSOR_REVISION=2505 | |
I: | |
I: IFORT_COMPILER12=C:\Program Files (x86)\Intel\Composer XE 2011 SP1.325\ | |
I: | |
I: PATH=C:\Users\dstuebe.ASA\Documents\HDF_Group\HDF5\1.8.11\x32\bin;C:\Program Files (x86)\Intel\Composer XE 2011 SP1.325\redist\intel64\mkl;C:\Program Files (x86)\Intel\Composer XE 2011 SP1\redist\ia32\tbb\vc10;C:\Program Files (x86)\Intel\Composer XE 2011 SP1\redist\intel64\tbb\vc10;C:\Program Files (x86)\Intel\Composer XE 2011 SP1\redist\intel64\ipp;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Intel\Composer XE 2011 SP1\redist\intel64\mkl;C:\Program Files (x86)\Intel\Composer XE 2011 SP1\redist\ia32\mkl;C:\Program Files (x86)\Common Files\Microsoft Shared\VSA\10.0\VsaEnv;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32\compiler;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\apache-ant-1.8.4\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\TortoiseGit\bin;C:\Program Files\Java\jdk1.7.0_06\bin;C:\Users\dstuebe.ASA\Documents\simple_jna\fortran\lib;C:\Program Files (x86)\CMake 2.8\bin | |
I: | |
I: OMPI_MCA_ORTE_NUM_NODES=1 | |
I: | |
I: OMPI_MCA_ORTE_ESS_JOBID=-112001023 | |
I: | |
I: LD_LIBRARY_PATH=C:\Python27\Lib\site-packages\mpi4py\bin/../lib:C:\Python27\Lib\site-packages\mpi4py\bin\..\lib | |
I: | |
I: WINDOWS_TRACING_FLAGS=3 | |
I: | |
I: SSH_AGENT_PID=5116 | |
I: | |
I: C_EM64T_REDIST12=C:\Program Files (x86)\Common Files\Intel\Shared Libraries\ | |
I: | |
I: TEMP=C:\Users\dstuebe.ASA\AppData\Local\Temp | |
I: | |
I: COMMONPROGRAMFILES(X86)=C:\Program Files (x86)\Common Files | |
I: | |
I: USERDOMAIN=ASA | |
I: | |
I: OMPI_MCA_ORTE_NUM_RESTARTS=0 | |
I: | |
I: PROGRAMFILES(X86)=C:\Program Files (x86) | |
I: | |
I: OMPI_MCA_ORTE_LOCAL_DAEMON_URI=4182966272.0;tcp://192.168.1.11:50570 | |
I: | |
I: ALLUSERSPROFILE=C:\ProgramData | |
I: | |
I: USERPROFILE=C:\Users\dstuebe.ASA | |
I: | |
I: LOCALAPPDATA=C:\Users\dstuebe.ASA\AppData\Local | |
I: | |
I: HOMEPATH=\Users\dstuebe.ASA | |
I: | |
I: OMPI_MCA_ORTE_PRECONDITION_TRANSPORTS=31ac250700000000-7d4deba100000000 | |
I: | |
I: F_IA32_REDIST12=C:\Program Files (x86)\Common Files\Intel\Shared Libraries\ | |
I: | |
I: JAVA_HOME=C:\Program Files\Java\jdk1.7.0_06 | |
I: | |
I: PROGRAMW6432=C:\Program Files | |
I: | |
I: USERNAME=DStuebe | |
I: | |
I: LOGONSERVER=\\ASAMSG | |
I: | |
I: SYSTEMROOT=C:\Windows | |
I: | |
I: SESSIONNAME=Console | |
I: | |
I: PROGRAMDATA=C:\ProgramData | |
I: | |
I: SSH_AUTH_SOCK=/tmp/ssh-kyboNC4240/agent.4240 | |
I: | |
I: OMPI_UNIVERSE_SIZE=1 | |
I: | |
I: OMPI_COMM_WORLD_NODE_RANK=0 | |
I: | |
I: ICPP_COMPILER12=C:\Program Files (x86)\Intel\Composer XE 2011 SP1\ | |
I: | |
I: USERDNSDOMAIN=ASA.LOCAL | |
I: | |
I: OMPI_COMM_WORLD_LOCAL_RANK=0 | |
I: | |
I: OMPI_COMM_WORLD_LOCAL_SIZE=1 | |
I: | |
I: WINDOWS_TRACING_LOGFILE=C:\BVTBin\Tests\installpackage\csilogfile.log | |
I: | |
I: PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC | |
I: | |
I: VTUNE_AMPLIFIER_XE_2011_DIR=C:\Program Files (x86)\Intel\VTune Amplifier XE 2011\ | |
I: | |
I: OMPI_MCA_ORTE_APP_NUM=0 | |
I: | |
I: FP_NO_HOST_CHECK=NO | |
I: | |
I: WINDIR=C:\Windows | |
I: | |
I: INSPECTOR_XE_2011_DIR=C:\Program Files (x86)\Intel\Inspector XE 2011\ | |
I: | |
I: OMPI_MCA_ORTE_ESS_VPID=0 | |
I: | |
I: OMPI_COMM_WORLD_RANK=0 | |
I: | |
I: HOMEDRIVE=C: | |
I: | |
I: ANT_HOME=C:\Program Files\apache-ant-1.8.4 | |
I: | |
I: SYSTEMDRIVE=C: | |
I: | |
I: OMPI_MCA_ORTE_ESS_NODE_RANK=0 | |
I: | |
I: PUBLIC=C:\Users\Public | |
I: | |
I: COMSPEC=C:\Windows\system32\cmd.exe | |
I: | |
I: NUMBER_OF_PROCESSORS=2 | |
I: | |
I: APPDATA=C:\Users\dstuebe.ASA\AppData\Roaming | |
I: | |
I: PWD=C:\Users\dstuebe.ASA\Documents\mapAppDev\process_test | |
I: | |
I: PROCESSOR_LEVEL=6 | |
I: | |
I: F_EM64T_REDIST12=C:\Program Files (x86)\Common Files\Intel\Shared Libraries\ | |
I: | |
I: OMPI_COMM_WORLD_SIZE=1 | |
I: | |
I: COMMONPROGRAMW6432=C:\Program Files\Common Files | |
I: | |
I: OS=Windows_NT | |
I: | |
I: OMPI_MCA_MPI_YIELD_WHEN_IDLE=1 | |
I: | |
I: OMPI_MCA_SHMEM_RUNTIME_QUERY_HINT=windows | |
Process Complete:0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
import java.util.Map; | |
import java.util.Map.Entry; | |
import javax.swing.text.html.HTMLDocument.Iterator; | |
public class TestProcess { | |
public static void main(String[] args) { | |
try { | |
System.out.println("Creating Process"); | |
int exitvalue = createProcess(); | |
System.out.println("Process Complete:" + exitvalue); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} catch (InterruptedException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
public static int createProcess() throws IOException, InterruptedException{ | |
ArrayList<String> processCommands = new ArrayList<String>(); | |
processCommands.add("C:\\Python27\\Lib\\site-packages\\mpi4py\\bin\\mpiexec.exe"); | |
processCommands.add("-n"); | |
processCommands.add("1"); | |
processCommands.add("C:\\Python27\\python.exe"); | |
//processCommands.add("bcast.py"); | |
processCommands.add("env.py"); | |
//processCommands.add("/Users/dstuebe/Documents/Dev/code/pyja_logger/printer.py"); | |
//processCommands.add("sleep"); | |
//processCommands.add("5"); | |
System.out.println("==== Process Builder Commands ==="); | |
for(String str : processCommands) | |
System.out.println(str); | |
ProcessBuilder processBuilder = new ProcessBuilder(processCommands); | |
Map<String, String> environ = processBuilder.environment(); | |
System.out.println("==== Process Builder Environment ==="); | |
for (Entry<String, String> entry : environ.entrySet()) { | |
System.out.println(entry.getKey() + " = " + entry.getValue()); | |
} | |
System.out.println("==== Process Output ==="); | |
Process process = processBuilder.start(); | |
final InputStream is = process.getInputStream(); | |
final InputStream es = process.getErrorStream(); | |
class RunnableStream implements Runnable{ | |
InputStream myStream; | |
String myname; | |
public RunnableStream(InputStream s, String name){ | |
myStream = s; | |
myname = name; | |
} | |
public void run() { | |
try { | |
BufferedReader reader = | |
new BufferedReader(new InputStreamReader(myStream)); | |
String line; | |
while ((line = reader.readLine()) != null) { | |
System.out.println(myname+line); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} finally { | |
try { | |
myStream.close(); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} | |
} | |
// the background thread watches the output from the process | |
Thread istreamThread = new Thread(new RunnableStream(is, "I: ")); | |
Thread estreamThread = new Thread(new RunnableStream(es, "E: ")); | |
estreamThread.start(); | |
istreamThread.start(); | |
int exitValue = process.waitFor(); | |
estreamThread.join(0); | |
istreamThread.join(0); | |
return exitValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment