File: Group.pyx

package info (click to toggle)
paraview 3.14.1-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 234,468 kB
  • sloc: cpp: 2,166,013; ansic: 801,575; xml: 58,068; tcl: 49,247; python: 43,091; java: 16,625; fortran: 12,224; sh: 11,722; yacc: 5,688; perl: 3,128; makefile: 2,228; lex: 1,311; lisp: 486; asm: 471; pascal: 228
file content (236 lines) | stat: -rw-r--r-- 6,941 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
cdef class Group:

    """
    Group
    """

    def __cinit__(self):
        self.ob_mpi = MPI_GROUP_NULL

    def __dealloc__(self):
        if not (self.flags & PyMPI_OWNED): return
        CHKERR( _del_Group(&self.ob_mpi) )

    def __richcmp__(self, other, int op):
        if not isinstance(self,  Group): return NotImplemented
        if not isinstance(other, Group): return NotImplemented
        cdef Group s = self, o = other
        if   op == 2: return (s.ob_mpi == o.ob_mpi)
        elif op == 3: return (s.ob_mpi != o.ob_mpi)
        else: raise TypeError(mpistr("only '==' and '!='"))

    def __nonzero__(self):
        return self.ob_mpi != MPI_GROUP_NULL

    # Group Accessors
    # ---------------

    def Get_size(self):
        """
        Return the size of a group
        """
        cdef int size = -1
        CHKERR( MPI_Group_size(self.ob_mpi, &size) )
        return size

    property size:
        """number of processes in group"""
        def __get__(self):
            return Group.Get_size(self)

    def Get_rank(self):
        """
        Return the rank of this process in a group
        """
        cdef int rank = -1
        CHKERR( MPI_Group_rank(self.ob_mpi, &rank) )
        return rank

    property rank:
        """rank of this process in group"""
        def __get__(self):
            return Group.Get_rank(self)

    @classmethod
    def Translate_ranks(cls, Group group1 not None, ranks1,
                        Group group2=None):
        """
        Translate the ranks of processes in
        one group to those in another group
        """
        cdef MPI_Group grp1 = MPI_GROUP_NULL
        cdef MPI_Group grp2 = MPI_GROUP_NULL
        cdef int i = 0, n = len(ranks1)
        cdef int *iranks1 = NULL, *iranks2 = NULL
        cdef object tmp1 = newarray_int(n, &iranks1)
        cdef object tmp2 = newarray_int(n, &iranks2)
        for i from 0 <= i < n: iranks1[i] = ranks1[i]
        #
        grp1 = group1.ob_mpi
        if group2 is not None:
            grp2 = group2.ob_mpi
        else:
            CHKERR( MPI_Comm_group(MPI_COMM_WORLD, &grp2) )
        try:
            CHKERR( MPI_Group_translate_ranks(grp1, n, iranks1,
                                              grp2, iranks2) )
        finally:
            if group2 is None:
                CHKERR( MPI_Group_free(&grp2) )
        #
        return [iranks2[i] for i from 0 <= i < n]

    @classmethod
    def Compare(cls,
                Group group1 not None,
                Group group2 not None):
        """
        Compare two groups
        """
        cdef int flag = MPI_UNEQUAL
        CHKERR( MPI_Group_compare(group1.ob_mpi, group2.ob_mpi, &flag) )
        return flag

    # Group Constructors
    # ------------------

    def Dup(self):
        """
        Duplicate a group
        """
        cdef Group group = type(self)()
        CHKERR( MPI_Group_union(self.ob_mpi, MPI_GROUP_EMPTY, &group.ob_mpi) )
        return group

    @classmethod
    def Union(cls,
              Group group1 not None,
              Group group2 not None):
        """
        Produce a group by combining
        two existing groups
        """
        cdef Group group = cls()
        CHKERR( MPI_Group_union(group1.ob_mpi, group2.ob_mpi, &group.ob_mpi) )
        return group

    @classmethod
    def Intersect(cls,
                  Group group1 not None,
                  Group group2 not None):
        """
        Produce a group as the intersection
        of two existing groups
        """
        cdef Group group = cls()
        CHKERR( MPI_Group_intersection(group1.ob_mpi, group2.ob_mpi, &group.ob_mpi) )
        return group

    @classmethod
    def Difference(cls,
                   Group group1 not None,
                   Group group2 not None):
        """
        Produce a group from the difference
        of two existing groups
        """
        cdef Group group = cls()
        CHKERR( MPI_Group_difference(group1.ob_mpi, group2.ob_mpi, &group.ob_mpi) )
        return group

    def Incl(self, ranks):
        """
        Produce a group by reordering an existing
        group and taking only listed members
        """
        cdef int i, n = len(ranks), *iranks = NULL
        cdef object tmp = newarray_int(n, &iranks)
        for i from 0 <= i < n: iranks[i] = ranks[i]
        cdef Group group = type(self)()
        CHKERR( MPI_Group_incl(self.ob_mpi, n, iranks, &group.ob_mpi) )
        return group

    def Excl(self, ranks):
        """
        Produce a group by reordering an existing
        group and taking only unlisted members
        """
        cdef int i, n = len(ranks), *iranks = NULL
        cdef object tmp = newarray_int(n, &iranks)
        for i from 0 <= i < n: iranks[i] = ranks[i]
        cdef Group group = type(self)()
        CHKERR( MPI_Group_excl(self.ob_mpi, n, iranks, &group.ob_mpi) )
        return group

    def Range_incl(self, ranks):
        """
        Create a new group from ranges of
        of ranks in an existing group
        """
        cdef int i, n = len(ranks), *p = NULL,
        cdef int (*ranges)[3] # = NULL ## XXX cython fails
        ranges = NULL
        cdef object tmp1 = newarray_int3(n, &ranges)
        for i from 0 <= i < n:
            p = <int*> ranges[i]
            p[0], p[1], p[2] = ranks[i]
        cdef Group group = type(self)()
        CHKERR( MPI_Group_range_incl(self.ob_mpi, n, ranges, &group.ob_mpi) )
        return group

    def Range_excl(self, ranks):
        """
        Create a new group by excluding ranges
        of processes from an existing group
        """
        cdef int i, n = len(ranks), *p = NULL,
        cdef int (*ranges)[3] # = NULL ## XXX cython fails
        ranges = NULL
        cdef object tmp1 = newarray_int3(n, &ranges)
        for i from 0 <= i < n:
            p = <int*> ranges[i]
            p[0], p[1], p[2] = ranks[i]
        cdef Group group = type(self)()
        CHKERR( MPI_Group_range_excl(self.ob_mpi, n, ranges, &group.ob_mpi) )
        return group

    # Group Destructor
    # ----------------

    def Free(self):
        """
        Free a group
        """
        if self.ob_mpi != MPI_GROUP_EMPTY:
            CHKERR( MPI_Group_free(&self.ob_mpi) )
        elif self is not __GROUP_EMPTY__:
            self.ob_mpi = MPI_GROUP_NULL
        else: CHKERR( MPI_ERR_GROUP )

    # Fortran Handle
    # --------------

    def py2f(self):
        """
        """
        return MPI_Group_c2f(self.ob_mpi)

    @classmethod
    def f2py(cls, arg):
        """
        """
        cdef Group group = cls()
        group.ob_mpi = MPI_Group_f2c(arg)
        return group



cdef Group __GROUP_NULL__  = _new_Group ( MPI_GROUP_NULL  )
cdef Group __GROUP_EMPTY__ = _new_Group ( MPI_GROUP_EMPTY )


# Predefined group handles
# ------------------------

GROUP_NULL  = __GROUP_NULL__   #: Null group handle
GROUP_EMPTY = __GROUP_EMPTY__  #: Empty group handle