File: e_cython_parallel.pyx

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (187 lines) | stat: -rw-r--r-- 4,505 bytes parent folder | download | duplicates (5)
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
# mode: error

cimport cython.parallel.parallel as p
from cython.parallel cimport something

import cython.parallel.parallel as p
from cython.parallel import something

from cython.parallel cimport prange

import cython.parallel

prange(1, 2, 3, schedule='dynamic')

cdef int i

with nogil, cython.parallel.parallel():
    for i in prange(10, schedule='invalid_schedule'):
        pass

with cython.parallel.parallel():
    print "hello world!"

cdef int *x = NULL

with nogil, cython.parallel.parallel():
    for j in prange(10):
        pass

    for x[1] in prange(10):
        pass

    for x in prange(10):
        pass

    with cython.parallel.parallel():
        pass

with nogil, cython.parallel.parallel:
    pass

cdef int y

for i in prange(10, nogil=True):
    i = y * 4
    y = i

for i in prange(10, nogil=True):
    y = i
    i = y * 4
    y = i


with nogil, cython.parallel.parallel():
    i = y
    y = i

for i in prange(10, nogil=True):
    y += i
    y *= i

with nogil, cython.parallel.parallel("invalid"):
    pass

with nogil, cython.parallel.parallel(invalid=True):
    pass

def f(x):
    cdef int i

    with nogil, cython.parallel.parallel():
        with gil:
            yield x

        for i in prange(10):
            with gil:
                yield x

# Disabled nesting:

for i in prange(10, nogil=True):
    for y in prange(10):
        pass

with nogil, cython.parallel.parallel():
    for i in prange(10):
        for i in prange(10):
            pass


# Assign to private from parallel block in prange:
cdef int myprivate1, myprivate2

with nogil, cython.parallel.parallel():
    myprivate1 = 1
    for i in prange(10):
        myprivate1 = 3
        myprivate2 = 4
    myprivate2 = 2

# Disallow parallel with block reductions:
i = 0
with nogil, cython.parallel.parallel():
    i += 1

# Use of privates after the parallel with block
with nogil, cython.parallel.parallel():
    i = 1

print i
i = 2
print i

# Reading of reduction variables in the prange block
cdef int sum = 0
for i in prange(10, nogil=True):
    sum += i
    with gil:
        print sum

for pyobj in prange("hello"):
    pass

from cython import parallel
with nogil, parallel.parallel():
    for i in parallel.prange(10):
        pass

cdef int[:] dst, src = object()
for i in prange(10, nogil=True):
    dst = src

for i in prange(10, nogil=True, chunksize=20):
    pass

for i in prange(10, nogil=True, schedule='static', chunksize=-1):
    pass

for i in prange(10, nogil=True, schedule='runtime', chunksize=10):
    pass

cdef int chunksize():
    return 10

for i in prange(10, nogil=True, schedule='static', chunksize=chunksize()):
    pass

with nogil, cython.parallel.parallel():
    with cython.parallel.parallel():
        pass


_ERRORS = u"""
3:8: cython.parallel.parallel is not a module
4:0: No such directive: cython.parallel.something
6:7: cython.parallel.parallel is not a module
7:0: No such directive: cython.parallel.something
13:6: prange() can only be used as part of a for loop
13:6: prange() can only be used without the GIL
18:19: Invalid schedule argument to prange: invalid_schedule
21:29: The parallel section may only be used without the GIL
27:8: target may not be a Python object as we don't have the GIL
30:9: Can only iterate over an iteration variable
33:8: Must be of numeric type, not int *
36:33: Nested parallel with blocks are disallowed
39:12: The parallel directive must be called
45:8: local variable 'y' referenced before assignment
55:8: local variable 'y' referenced before assignment
60:4: Reduction operator '*' is inconsistent with previous reduction operator '+'
62:36: cython.parallel.parallel() does not take positional arguments
65:36: Invalid keyword argument: invalid
73:12: 'yield' not allowed in parallel sections
77:16: 'yield' not allowed in parallel sections
97:8: Cannot assign to private of outer parallel block
98:8: Cannot assign to private of outer parallel block
104:4: Reductions not allowed for parallel blocks
110:6: local variable 'i' referenced before assignment
119:14: Cannot read reduction variable in loop body
121:19: prange() can only be used without the GIL
121:20: stop argument must be numeric
131:4: Memoryview slices can only be shared in parallel sections
133:42: Must provide schedule with chunksize
136:62: Chunksize must not be negative
139:62: Chunksize not valid for the schedule runtime
145:70: Calling gil-requiring function not allowed without gil
149:33: Nested parallel with blocks are disallowed
"""