public
Created

Running OpenMPI process from Java

  • Download Gist
TestProcess.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
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;
}
}
bcast.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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)
env.py
Python
1 2 3 4 5
#!/usr/bin/env python
import os
 
if __name__ == '__main__':
print os.linesep.join('='.join((key, value)) for key, value in os.environ.items())
ouptput.log
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.