Mixed-Language Programming with XcalableMP
153
void foo(long a[3], long b[3]){
#pragma xmp nodes p[*]
:
}
from mpi4py import MPI
import xmp
lib = xmp.Lib("bar.so")
comm = MPI.COMM_WORLD
args = ([1,2,3], [4,5,6])
job = lib.call(comm, "foo", args)
1
2
3
4
5
6
7
8
Fig. 4 Example of calling XMP program (bar.c) from parallel Python program (bar.py) [19]
xmp.Lib.call() calls a parallel XMP program. This function performs initialization
and finalization for an XMP environment internally.
To use the features, the Omni compiler runtime library must be a shared library.
Therefore, we develop a new compile process to create a shared library for Omni
compiler. When adding an option “--enable-shared” to “./configure” as
follows, shared libraries are created.
$ ./configure --enable-shared
An example of compilation and execution using Omni compiler is as follows.
A shared library is created by “xmpcc” command from a user program. Compile
options used to create the shared library depend on a native compiler (e.g., “-fPIC
-shard” if the native compiler is gcc). The execution binary is executed via
Python.
$ xmpcc -fPIC -shared bar.c -o bar.so
$ mpirun -np 4 python bar.py
3.3.2 From Sequential Python Program
Figure 5 shows an example of calling an XMP program from a sequential Python
program. In line 6, xmp.Lib.spawn() calls a parallel XMP program. The first
argument is number of nodes in XMP. The last argument is an option for asynchronous operation. If it is true, processing may return to python before “foo()”
completes. In line 7, xmp.Lib.wait() waits until “foo()” completes. In line 9,
xmp.Lib.elapse_time() returns processing time for “foo()”.
153
void foo(long a[3], long b[3]){
#pragma xmp nodes p[*]
:
}
from mpi4py import MPI
import xmp
lib = xmp.Lib("bar.so")
comm = MPI.COMM_WORLD
args = ([1,2,3], [4,5,6])
job = lib.call(comm, "foo", args)
1
2
3
4
5
6
7
8
Fig. 4 Example of calling XMP program (bar.c) from parallel Python program (bar.py) [19]
xmp.Lib.call() calls a parallel XMP program. This function performs initialization
and finalization for an XMP environment internally.
To use the features, the Omni compiler runtime library must be a shared library.
Therefore, we develop a new compile process to create a shared library for Omni
compiler. When adding an option “--enable-shared” to “./configure” as
follows, shared libraries are created.
$ ./configure --enable-shared
An example of compilation and execution using Omni compiler is as follows.
A shared library is created by “xmpcc” command from a user program. Compile
options used to create the shared library depend on a native compiler (e.g., “-fPIC
-shard” if the native compiler is gcc). The execution binary is executed via
Python.
$ xmpcc -fPIC -shared bar.c -o bar.so
$ mpirun -np 4 python bar.py
3.3.2 From Sequential Python Program
Figure 5 shows an example of calling an XMP program from a sequential Python
program. In line 6, xmp.Lib.spawn() calls a parallel XMP program. The first
argument is number of nodes in XMP. The last argument is an option for asynchronous operation. If it is true, processing may return to python before “foo()”
completes. In line 7, xmp.Lib.wait() waits until “foo()” completes. In line 9,
xmp.Lib.elapse_time() returns processing time for “foo()”.
