diff --git a/buffered.go b/MPI/buffered.go similarity index 100% rename from buffered.go rename to MPI/buffered.go diff --git a/cart.go b/MPI/cart.go similarity index 100% rename from cart.go rename to MPI/cart.go diff --git a/comm.go b/MPI/comm.go similarity index 100% rename from comm.go rename to MPI/comm.go diff --git a/const-helper.h b/MPI/const-helper.h similarity index 100% rename from const-helper.h rename to MPI/const-helper.h diff --git a/const.go b/MPI/const.go similarity index 100% rename from const.go rename to MPI/const.go diff --git a/datatype-helper.h b/MPI/datatype-helper.h similarity index 100% rename from datatype-helper.h rename to MPI/datatype-helper.h diff --git a/datatype.go b/MPI/datatype.go similarity index 100% rename from datatype.go rename to MPI/datatype.go diff --git a/error.go b/MPI/error.go similarity index 100% rename from error.go rename to MPI/error.go diff --git a/error_openmpi.go b/MPI/error_openmpi.go similarity index 100% rename from error_openmpi.go rename to MPI/error_openmpi.go diff --git a/file.go b/MPI/file.go similarity index 100% rename from file.go rename to MPI/file.go diff --git a/go-helper.go b/MPI/go-helper.go similarity index 100% rename from go-helper.go rename to MPI/go-helper.go diff --git a/go-helper_test.go b/MPI/go-helper_test.go similarity index 100% rename from go-helper_test.go rename to MPI/go-helper_test.go diff --git a/group.go b/MPI/group.go similarity index 100% rename from group.go rename to MPI/group.go diff --git a/info.go b/MPI/info.go similarity index 100% rename from info.go rename to MPI/info.go diff --git a/init.go b/MPI/init.go similarity index 78% rename from init.go rename to MPI/init.go index aa7702a..ae63e58 100644 --- a/init.go +++ b/MPI/init.go @@ -47,6 +47,29 @@ func Init(argv *[]string) int { return int(err) } +//Init +//Initialize MPI on different thread levels +func Init_thread(argv *[]string, required int) (int, int) { + + argc := len(*argv) + c_argc := C.int(argc) + + c_argv := make([]*C.char, argc) + for index, value := range *argv { + c_argv[index] = C.CString(value) + defer C.free(unsafe.Pointer(c_argv[index])) + } + + var provided int + err := C.MPI_Init_thread(&c_argc, (***C.char)(unsafe.Pointer(&c_argv)), C.int(required), (*C.int)(unsafe.Pointer(&provided))) + goargs := make([]string, c_argc) + for i := 0; i < int(c_argc); i++ { + goargs[i] = C.GoString(c_argv[i]) + } + *argv = goargs + return provided, int(err) +} + //Initialized //Indicates whether MPI_Init has been called. func Initialized(flag *int) int { diff --git a/mem.go b/MPI/mem.go similarity index 100% rename from mem.go rename to MPI/mem.go diff --git a/misc.go b/MPI/misc.go similarity index 100% rename from misc.go rename to MPI/misc.go diff --git a/net.go b/MPI/net.go similarity index 100% rename from net.go rename to MPI/net.go diff --git a/operations-helper.h b/MPI/operations-helper.h similarity index 100% rename from operations-helper.h rename to MPI/operations-helper.h diff --git a/operations.go b/MPI/operations.go similarity index 100% rename from operations.go rename to MPI/operations.go diff --git a/tests.go b/MPI/tests.go similarity index 100% rename from tests.go rename to MPI/tests.go diff --git a/topo.go b/MPI/topo.go similarity index 100% rename from topo.go rename to MPI/topo.go diff --git a/type.go b/MPI/type.go similarity index 100% rename from type.go rename to MPI/type.go diff --git a/win.go b/MPI/win.go similarity index 100% rename from win.go rename to MPI/win.go diff --git a/README.md b/README.md index bd13723..c71a02f 100644 --- a/README.md +++ b/README.md @@ -7,37 +7,30 @@ go-mpi are GO bindings for the Message Passing Interface Open MPI and MPICH version 2. -To tell go where to look for the MPI library use the CGO_LDFALG environment variable. The following instructions uses the default path for Open MPI and MPICH. - -For Open MPI: -```sh -export CGO_LDFLAGS='-L/usr/lib/openmpi -lmpi' -go get -tags openmpi github.com/JohannWeging/go-mpi -``` - -For MPICH: -```sh -export CGO_LDFLAGS='-L/usr/lib/ -lmpich' -go get -tags mpich github.com/JohannWeging/go-mpi -``` +To tell go where to look for mpi.h and mpi library, use the CGO_CFLAGS and CGO_LDFALG environment variable to indicate respectively. You can find paths of mpi.h and mpi library through command: + + $ mpichversion + + +Assume mpi.h dir is "/usr/local/include", mpi library dir is "/usr/local/lib", you could compile go-mpi/MPI like the following: + + export CGO_CFLAGS='-I/usr/local/include' + export CGO_LDFLAGS='-L/usr/local/lib -lmpich' + go install go-mpi/MPI + + ## Syntax -The syntax is similar to the C syntax of MPI. -``` -.Mpi_function(arguments) -``` +Firstly you should import "go-mpi/MPI" in your go-mpi application. + + import "go-mpi/MPI" + -If the bindings are imported as "MPI": -
-  err = MPI.Init(os.Args)
-
+The syntax of MPI invokes in go-mpi is similar to it in C-binding MPI implementations. -Output parameter like request objects are returned by the function and not passed as pointers inside the arguments. + .Mpi_function(arguments) -
-  C:
-  err = MPI_Irecv(recvBuffer, count, MPI_INT, 0, 1, MPI_COMM_WROLD, &request)
+For example:
 
-  GO:
-  err = MPI.Irecv(recvBuffer, count, MPI.INT, 0, 1, MPI.COMM_WORLD, &request)
-
+ err = MPI.Init(&os.Args) + err = MPI.Irecv(recvBuffer, count, MPI.INT, 0, 1, MPI.COMM_WORLD, &request)