MPI_dummy.py 2.68 KB
Newer Older
ultimanet's avatar
ultimanet committed
1
2
3
4
5
6
# -*- coding: utf-8 -*-

import numpy as np

def MIN():
    return np.min
7

ultimanet's avatar
ultimanet committed
8
9
def MAX():
    return np.max
10

ultimanet's avatar
ultimanet committed
11
def SUM():
12
    return np.sum
ultimanet's avatar
ultimanet committed
13
14
15
16
17
18
19



class _COMM_WORLD():
    def __init__(self):
        self.rank = 0
        self.size = 1
20

ultimanet's avatar
ultimanet committed
21
22
    def Get_rank(self):
        return self.rank
23

ultimanet's avatar
ultimanet committed
24
25
    def Get_size(self):
        return self.size
26

Ultima's avatar
Ultima committed
27
    def _scattergather_helper(self, sendbuf, recvbuf=None, **kwargs):
28
29
        sendbuf = self._unwrapper(sendbuf)
        recvbuf = self._unwrapper(recvbuf)
30
        if recvbuf != None:
ultimanet's avatar
ultimanet committed
31
32
33
34
35
            recvbuf[:] = sendbuf
            return recvbuf
        else:
            recvbuf = np.copy(sendbuf)
            return recvbuf
36

ultimanet's avatar
ultimanet committed
37
38
    def bcast(self, sendbuf, *args, **kwargs):
        return sendbuf
39

ultimanet's avatar
ultimanet committed
40
41
    def Bcast(self, sendbuf, *args, **kwargs):
        return sendbuf
42

43
44
    def scatter(self, sendbuf, *args, **kwargs):
        return sendbuf[0]
45

ultimanet's avatar
ultimanet committed
46
47
    def Scatter(self, *args, **kwargs):
        return self._scattergather_helper(*args, **kwargs)
48

ultimanet's avatar
ultimanet committed
49
50
51
    def Scatterv(self, *args, **kwargs):
        return self._scattergather_helper(*args, **kwargs)

52
53
    def gather(self, sendbuf, *args, **kwargs):
        return [sendbuf,]
54

ultimanet's avatar
ultimanet committed
55
56
57
58
59
60
    def Gather(self, *args, **kwargs):
        return self._scattergather_helper(*args, **kwargs)

    def Gatherv(self, *args, **kwargs):
        return self._scattergather_helper(*args, **kwargs)

61
62
    def allgather(self, sendbuf, *args, **kwargs):
        return [sendbuf,]
63

ultimanet's avatar
ultimanet committed
64
65
    def Allgather(self, *args, **kwargs):
        return self._scattergather_helper(*args, **kwargs)
66

ultimanet's avatar
ultimanet committed
67
68
    def Allgatherv(self, *args, **kwargs):
        return self._scattergather_helper(*args, **kwargs)
69

ultimanet's avatar
ultimanet committed
70
    def Allreduce(self, sendbuf, recvbuf, op, **kwargs):
Ultima's avatar
Ultima committed
71
        recvbuf[:] = op(sendbuf)
ultimanet's avatar
ultimanet committed
72
        return recvbuf
73

ultimanet's avatar
ultimanet committed
74
    def allreduce(self, sendbuf, recvbuf, op, **kwargs):
Ultima's avatar
Ultima committed
75
        recvbuf[:] = op(sendbuf)
ultimanet's avatar
ultimanet committed
76
        return recvbuf
Ultima's avatar
Ultima committed
77
78
79

    def sendrecv(self, sendobj, **kwargs):
        return sendobj
80

ultimanet's avatar
ultimanet committed
81
82
83
84
85
    def _unwrapper(self, x):
        if isinstance(x, list):
            return x[0]
        else:
            return x
86

87
88
    def Barrier(self):
        pass
ultimanet's avatar
ultimanet committed
89
90
91
92

class _datatype():
    def __init__(self, name):
        self.name = str(name)
Ultimanet's avatar
Ultimanet committed
93

94
BYTE = _datatype('MPI_BYTE')
ultimanet's avatar
ultimanet committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
SHORT = _datatype('MPI_SHORT')
UNSIGNED_SHORT = _datatype("MPI_UNSIGNED_SHORT")
UNSIGNED_INT = _datatype("MPI_UNSIGNED_INT")
INT = _datatype("MPI_INT")
LONG = _datatype("MPI_LONG")
UNSIGNED_LONG = _datatype("MPI_UNSIGNED_LONG")
LONG_LONG = _datatype("MPI_LONG_LONG")
UNSIGNED_LONG_LONG = _datatype("MPI_UNSIGNED_LONG_LONG")
FLOAT = _datatype("MPI_FLOAT")
DOUBLE = _datatype("MPI_DOUBLE")
LONG_DOUBLE = _datatype("MPI_LONG_DOUBLE")
COMPLEX = _datatype("MPI_COMPLEX")
DOUBLE_COMPLEX = _datatype("MPI_DOUBLE_COMPLEX")

109

ultimanet's avatar
ultimanet committed
110
COMM_WORLD = _COMM_WORLD()
111
112
113
114
115
116
117
118
119
120
121