forked from yoo/go-mpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo-helper_test.go
70 lines (56 loc) · 1.13 KB
/
go-helper_test.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
package MPI
import (
"fmt"
"os"
"testing"
)
func TestType_create_gostruct(T *testing.T) {
err := Init(&os.Args)
if err != SUCCESS {
T.Error("MPI.Init failed.\n")
}
rank, err := Comm_rank(COMM_WORLD)
if err != SUCCESS {
T.Error("MPI.Comm_rank failed.\n")
Abort(COMM_WORLD, err)
}
type embed struct {
f1 int
}
type testStruct struct {
f1 int
f2 float64
f3 [10]byte
f4 embed
}
var ts testStruct
if rank == 0 {
ts.f1 = 1
ts.f2 = 2.0
ts.f3 = [10]byte{'f', 'o', 'o'}
ts.f4.f1 = 1
}
MPI_testStruct, err := Type_create_gostruct(ts)
Type_commit(&MPI_testStruct)
if err != SUCCESS {
T.Error("Failed to call Type_create_gostruct.")
Abort(COMM_WORLD, err)
}
if rank == 0 {
Send(&ts, 1, MPI_testStruct, 1, 1, COMM_WORLD)
} else {
Recv(&ts, 1, MPI_testStruct, 0, 1, COMM_WORLD)
}
if rank != 0 {
var tsValid testStruct
tsValid.f1 = 1
tsValid.f2 = 2.0
tsValid.f3 = [10]byte{'f', 'o', 'o'}
tsValid.f4.f1 = 1
tsString := fmt.Sprintf("%#v", ts)
tsValidString := fmt.Sprintf("%#v", tsValid)
if tsString != tsValidString {
T.Errorf("Expected: %s\n,was: %s\n", tsValidString, tsString)
}
}
}