File: Op.pyx

package info (click to toggle)
paraview 3.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 173,864 kB
  • ctags: 192,754
  • sloc: cpp: 1,497,065; ansic: 607,818; tcl: 47,394; xml: 47,108; python: 29,870; perl: 3,117; java: 2,428; yacc: 1,853; sh: 833; asm: 471; lex: 393; pascal: 228; makefile: 189; fortran: 31
file content (99 lines) | stat: -rw-r--r-- 2,750 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
cdef class Op:

    """
    Op
    """

    def __cinit__(self):
        self.ob_mpi = MPI_OP_NULL

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

    def __richcmp__(self, other, int op):
        if not isinstance(self,  Op): return NotImplemented
        if not isinstance(other, Op): return NotImplemented
        cdef Op 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_OP_NULL

    def __call__(self, x, y):
        if self.ob_func != NULL:
            return self.ob_func(x, y)
        else:
            return self.ob_callable(x, y)

    @classmethod
    def Create(cls, function, bint commute=False):
        """
        Create a user-defined operation
        """
        cdef Op op = cls()
        op.ob_mpi = MPI_OP_NULL
        op.ob_callable = function
        op.ob_commute  = commute

    def Free(self):
        """
        Free the operation
        """
        CHKERR( MPI_Op_free(&self.ob_mpi) )
        self.ob_callable = None
        self.ob_commute  = False

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

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

    @classmethod
    def f2py(cls, arg):
        """
        """
        cdef Op op = cls()
        op.ob_mpi = MPI_Op_f2c(arg)
        return op



cdef Op __OP_NULL__ = _new_Op( MPI_OP_NULL )
cdef Op __MAX__     = _new_Op( MPI_MAX     )
cdef Op __MIN__     = _new_Op( MPI_MIN     )
cdef Op __SUM__     = _new_Op( MPI_SUM     )
cdef Op __PROD__    = _new_Op( MPI_PROD    )
cdef Op __LAND__    = _new_Op( MPI_LAND    )
cdef Op __BAND__    = _new_Op( MPI_BAND    )
cdef Op __LOR__     = _new_Op( MPI_LOR     )
cdef Op __BOR__     = _new_Op( MPI_BOR     )
cdef Op __LXOR__    = _new_Op( MPI_LXOR    )
cdef Op __BXOR__    = _new_Op( MPI_BXOR    )
cdef Op __MAXLOC__  = _new_Op( MPI_MAXLOC  )
cdef Op __MINLOC__  = _new_Op( MPI_MINLOC  )
cdef Op __REPLACE__ = _new_Op( MPI_REPLACE )


# Predefined operation handles
# ----------------------------

OP_NULL = __OP_NULL__  #: Null
MAX     = __MAX__      #: Maximum
MIN     = __MIN__      #: Minimum
SUM     = __SUM__      #: Sum
PROD    = __PROD__     #: Product
LAND    = __LAND__     #: Logical and
BAND    = __BAND__     #: Bit-wise and
LOR     = __LOR__      #: Logical or
BOR     = __BOR__      #: Bit-wise or
LXOR    = __LXOR__     #: Logical xor
BXOR    = __BXOR__     #: Bit-wise xor
MAXLOC  = __MAXLOC__   #: Maximum and location
MINLOC  = __MINLOC__   #: Minimum and location
REPLACE = __REPLACE__  #: Replace (for RMA)