File: test_0.py

package info (click to toggle)
mpi4py 4.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,540 kB
  • sloc: python: 34,465; ansic: 16,475; makefile: 614; sh: 325; cpp: 193; f90: 178
file content (130 lines) | stat: -rw-r--r-- 2,614 bytes parent folder | download | duplicates (2)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import os
import sys

from mpi4py import rc

vmap = {
    "true": True,
    "false": False,
    "0": 0,
    "1": 1,
    "1024": 1024,
}
for arg in sys.argv[1:]:
    attr, value = arg.split("=")
    setattr(rc, attr, vmap.get(value, value))

if rc.errors == "abort":
    rc.initialize = False

from mpi4py import MPI  # noqa: E402

if rc.errors == "abort":
    vendor, version = MPI.get_vendor()
    if vendor == "Intel MPI":
        if version[:2] < (2021, 11):
            sys.exit(0)
    if vendor == "MPICH":
        if version[:2] < (4, 1):
            sys.exit(0)
    if vendor == "Open MPI":
        if version[:2] < (5, 0):
            sys.exit(0)


def check_errhandler(obj):
    if rc.errors == "default":
        if isinstance(obj, MPI.File):
            check_eh = MPI.ERRORS_RETURN
        else:
            check_eh = MPI.ERRORS_ARE_FATAL
    elif rc.errors == "exception":
        check_eh = MPI.ERRORS_RETURN
    elif rc.errors == "abort":
        check_eh = MPI.ERRORS_ABORT
        if MPI.ERRORS_ABORT == MPI.ERRHANDLER_NULL:
            check_eh = MPI.ERRORS_ARE_FATAL
    elif rc.errors == "fatal":
        check_eh = MPI.ERRORS_ARE_FATAL
    else:
        assert 0
    eh = obj.Get_errhandler()
    try:
        assert eh == check_eh
    finally:
        if eh != MPI.ERRHANDLER_NULL:
            eh.Free()


if not MPI.Is_initialized():
    MPI.Init()


try:
    session = MPI.Session.Init()
    try:
        check_errhandler(session)
    finally:
        session.Finalize()
except NotImplementedError:
    pass
except MPI.Exception:
    pass


try:
    for commbase in (MPI.COMM_SELF, MPI.COMM_WORLD):
        check_errhandler(commbase)
        comm = commbase.Dup()
        try:
            check_errhandler(comm)
        finally:
            comm.Free()
except NotImplementedError:
    pass
except MPI.Exception:
    pass


weh = MPI.COMM_SELF.Get_errhandler()
MPI.COMM_SELF.Set_errhandler(MPI.ERRORS_RETURN)
try:
    win = MPI.Win.Create(
        MPI.BOTTOM,
        1,
        MPI.INFO_NULL,
        MPI.COMM_SELF,
    )
    try:
        check_errhandler(win)
    finally:
        win.Free()
except NotImplementedError:
    pass
except MPI.Exception:
    pass
finally:
    MPI.COMM_SELF.Set_errhandler(weh)
    weh.Free()


try:
    # check_errhandler(MPI.FILE_NULL)  # TODO
    file = MPI.File.Open(
        MPI.COMM_SELF,
        os.devnull,
        MPI.MODE_WRONLY,
        MPI.INFO_NULL,
    )
    try:
        check_errhandler(file)
    finally:
        file.Close()
except NotImplementedError:
    pass
except MPI.Exception:
    pass


if not MPI.Is_finalized():
    MPI.Finalize()