From 39d7125257c10d5664ed67dc4f3cae3502acddd2 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Thu, 7 May 2015 00:54:47 +0800 Subject: [PATCH 1/3] Fix a error and update compiling details for convenient usages. Move the source file to a folder named "MPI" respected to go package naming style. --- buffered.go => MPI/buffered.go | 0 cart.go => MPI/cart.go | 0 comm.go => MPI/comm.go | 0 const-helper.h => MPI/const-helper.h | 0 const.go => MPI/const.go | 0 datatype-helper.h => MPI/datatype-helper.h | 0 datatype.go => MPI/datatype.go | 0 error.go => MPI/error.go | 0 error_openmpi.go => MPI/error_openmpi.go | 0 file.go => MPI/file.go | 0 go-helper.go => MPI/go-helper.go | 0 go-helper_test.go => MPI/go-helper_test.go | 0 group.go => MPI/group.go | 0 info.go => MPI/info.go | 0 init.go => MPI/init.go | 0 mem.go => MPI/mem.go | 0 misc.go => MPI/misc.go | 0 net.go => MPI/net.go | 0 .../operations-helper.h | 0 operations.go => MPI/operations.go | 0 tests.go => MPI/tests.go | 0 topo.go => MPI/topo.go | 0 type.go => MPI/type.go | 0 win.go => MPI/win.go | 0 README.md | 23 ++++++++++--------- 25 files changed, 12 insertions(+), 11 deletions(-) rename buffered.go => MPI/buffered.go (100%) rename cart.go => MPI/cart.go (100%) rename comm.go => MPI/comm.go (100%) rename const-helper.h => MPI/const-helper.h (100%) rename const.go => MPI/const.go (100%) rename datatype-helper.h => MPI/datatype-helper.h (100%) rename datatype.go => MPI/datatype.go (100%) rename error.go => MPI/error.go (100%) rename error_openmpi.go => MPI/error_openmpi.go (100%) rename file.go => MPI/file.go (100%) rename go-helper.go => MPI/go-helper.go (100%) rename go-helper_test.go => MPI/go-helper_test.go (100%) rename group.go => MPI/group.go (100%) rename info.go => MPI/info.go (100%) rename init.go => MPI/init.go (100%) rename mem.go => MPI/mem.go (100%) rename misc.go => MPI/misc.go (100%) rename net.go => MPI/net.go (100%) rename operations-helper.h => MPI/operations-helper.h (100%) rename operations.go => MPI/operations.go (100%) rename tests.go => MPI/tests.go (100%) rename topo.go => MPI/topo.go (100%) rename type.go => MPI/type.go (100%) rename win.go => MPI/win.go (100%) 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 100% rename from init.go rename to MPI/init.go 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..54dadfd 100644 --- a/README.md +++ b/README.md @@ -7,29 +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. +To tell go where to look for mpi.h and mpi library, use the CGO_CFLAGS and CGO_LDFALG environment variable to indicate respectively. -For Open MPI: +Assume your mpi.h dir is "/usr/local/include", mpi library dir is "/usr/local/lib" and you use mpich, you could compile go-mpi/MPI like the following: ```sh -export CGO_LDFLAGS='-L/usr/lib/openmpi -lmpi' -go get -tags openmpi github.com/JohannWeging/go-mpi +export CGO_CFLGAS='-I/usr/local/include' +export CGO_LDFLAGS='-L/usr/local/lib -lmpich' +go install go-mpi/MPI ``` -For MPICH: -```sh -export CGO_LDFLAGS='-L/usr/lib/ -lmpich' -go get -tags mpich github.com/JohannWeging/go-mpi -``` ## Syntax -The syntax is similar to the C syntax of MPI. +Firstly you should import "go-mpi/MPI" in your go-mpi application. +``` +import "go-mpi/MPI" +``` + +The syntax of MPI invokes in go-mpi is similar to it in C-binding MPI implementations. ``` .Mpi_function(arguments) ``` If the bindings are imported as "MPI":
-  err = MPI.Init(os.Args)
+  err = MPI.Init(&os.Args)
 
Output parameter like request objects are returned by the function and not passed as pointers inside the arguments. From a5d9b03a37c719b2dc64fdc3eceb758faee186da Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 24 May 2015 15:47:36 +0800 Subject: [PATCH 2/3] Add support for multiple thread. * Add interface: MPI.Init_thread() Test passed --- MPI/init.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/MPI/init.go b/MPI/init.go index aa7702a..ae63e58 100644 --- a/MPI/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 { From 22bc360d276af836233736f559108a886d46965f Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 24 May 2015 16:09:16 +0800 Subject: [PATCH 3/3] Refine README --- README.md | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 54dadfd..c71a02f 100644 --- a/README.md +++ b/README.md @@ -7,38 +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 mpi.h and mpi library, use the CGO_CFLAGS and CGO_LDFALG environment variable to indicate respectively. +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 -Assume your mpi.h dir is "/usr/local/include", mpi library dir is "/usr/local/lib" and you use mpich, you could compile go-mpi/MPI like the following: -```sh -export CGO_CFLGAS='-I/usr/local/include' -export CGO_LDFLAGS='-L/usr/local/lib -lmpich' -go install go-mpi/MPI -``` ## Syntax Firstly you should import "go-mpi/MPI" in your go-mpi application. -``` -import "go-mpi/MPI" -``` -The syntax of MPI invokes in go-mpi is similar to it in C-binding MPI implementations. -``` -.Mpi_function(arguments) -``` + 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)