-
Notifications
You must be signed in to change notification settings - Fork 14
/
init.go
97 lines (73 loc) · 2.17 KB
/
init.go
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
// Copyright (c) 2013 Alexander Beifuß <[email protected]>
// Johann Weging <[email protected]>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package MPI
/*
#include <mpi.h>
#include <stdlib.h>
*/
import "C"
import (
"unsafe"
)
//Init
//Initializes the MPI execution environment
func Init(argv *[]string) 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]))
}
err := C.MPI_Init(&c_argc, (***C.char)(unsafe.Pointer(&c_argv)))
goargs := make([]string, c_argc)
for i := 0; i < int(c_argc); i++ {
goargs[i] = C.GoString(c_argv[i])
}
*argv = goargs
return int(err)
}
//Initialized
//Indicates whether MPI_Init has been called.
func Initialized(flag *int) int {
err := C.MPI_Initialized((*C.int)(unsafe.Pointer(flag)))
return int(err)
}
//Finalize
//Terminates MPI execution environment.
func Finalize() int {
err := C.MPI_Finalize()
return int(err)
}
//Finalized
//Checks whether Finalize has completed.
func Finalized() (int, int) {
var flag C.int
err := C.MPI_Finalized(&flag)
return int(flag), int(err)
}
//Abort
//Terminates MPI execution environment.
func Abort(comm Comm, errorcode int) int {
err := C.MPI_Abort(C.MPI_Comm(comm), C.int(errorcode))
return int(err)
}
//Cancel
//Cancels a communication request.
func Cancel(request Request) int {
cRequest := C.MPI_Request(request)
err := C.MPI_Cancel(&cRequest)
return int(err)
}