Commit 36ab0511 authored by Boxiang Sun's avatar Boxiang Sun

Test

parent 1b0999f9
This source diff could not be displayed because it is too large. You can view the blob instead.
<!DOCTYPE html>
<!-- Generated by Cython 0.29b1 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cython: test.pyx</title>
<style type="text/css">
body.cython { font-family: courier; font-size: 12; }
.cython.tag { }
.cython.line { margin: 0em }
.cython.code { font-size: 9; color: #444444; display: none; margin: 0px 0px 0px 8px; border-left: 8px none; }
.cython.line .run { background-color: #B0FFB0; }
.cython.line .mis { background-color: #FFB0B0; }
.cython.code.run { border-left: 8px solid #B0FFB0; }
.cython.code.mis { border-left: 8px solid #FFB0B0; }
.cython.code .py_c_api { color: red; }
.cython.code .py_macro_api { color: #FF7000; }
.cython.code .pyx_c_api { color: #FF3000; }
.cython.code .pyx_macro_api { color: #FF7000; }
.cython.code .refnanny { color: #FFA000; }
.cython.code .trace { color: #FFA000; }
.cython.code .error_goto { color: #FFA000; }
.cython.code .coerce { color: #008000; border: 1px dotted #008000 }
.cython.code .py_attr { color: #FF0000; font-weight: bold; }
.cython.code .c_attr { color: #0000FF; }
.cython.code .py_call { color: #FF0000; font-weight: bold; }
.cython.code .c_call { color: #0000FF; }
.cython.score-0 {background-color: #FFFFff;}
.cython.score-1 {background-color: #FFFFe7;}
.cython.score-2 {background-color: #FFFFd4;}
.cython.score-3 {background-color: #FFFFc4;}
.cython.score-4 {background-color: #FFFFb6;}
.cython.score-5 {background-color: #FFFFaa;}
.cython.score-6 {background-color: #FFFF9f;}
.cython.score-7 {background-color: #FFFF96;}
.cython.score-8 {background-color: #FFFF8d;}
.cython.score-9 {background-color: #FFFF86;}
.cython.score-10 {background-color: #FFFF7f;}
.cython.score-11 {background-color: #FFFF79;}
.cython.score-12 {background-color: #FFFF73;}
.cython.score-13 {background-color: #FFFF6e;}
.cython.score-14 {background-color: #FFFF6a;}
.cython.score-15 {background-color: #FFFF66;}
.cython.score-16 {background-color: #FFFF62;}
.cython.score-17 {background-color: #FFFF5e;}
.cython.score-18 {background-color: #FFFF5b;}
.cython.score-19 {background-color: #FFFF57;}
.cython.score-20 {background-color: #FFFF55;}
.cython.score-21 {background-color: #FFFF52;}
.cython.score-22 {background-color: #FFFF4f;}
.cython.score-23 {background-color: #FFFF4d;}
.cython.score-24 {background-color: #FFFF4b;}
.cython.score-25 {background-color: #FFFF48;}
.cython.score-26 {background-color: #FFFF46;}
.cython.score-27 {background-color: #FFFF44;}
.cython.score-28 {background-color: #FFFF43;}
.cython.score-29 {background-color: #FFFF41;}
.cython.score-30 {background-color: #FFFF3f;}
.cython.score-31 {background-color: #FFFF3e;}
.cython.score-32 {background-color: #FFFF3c;}
.cython.score-33 {background-color: #FFFF3b;}
.cython.score-34 {background-color: #FFFF39;}
.cython.score-35 {background-color: #FFFF38;}
.cython.score-36 {background-color: #FFFF37;}
.cython.score-37 {background-color: #FFFF36;}
.cython.score-38 {background-color: #FFFF35;}
.cython.score-39 {background-color: #FFFF34;}
.cython.score-40 {background-color: #FFFF33;}
.cython.score-41 {background-color: #FFFF32;}
.cython.score-42 {background-color: #FFFF31;}
.cython.score-43 {background-color: #FFFF30;}
.cython.score-44 {background-color: #FFFF2f;}
.cython.score-45 {background-color: #FFFF2e;}
.cython.score-46 {background-color: #FFFF2d;}
.cython.score-47 {background-color: #FFFF2c;}
.cython.score-48 {background-color: #FFFF2b;}
.cython.score-49 {background-color: #FFFF2b;}
.cython.score-50 {background-color: #FFFF2a;}
.cython.score-51 {background-color: #FFFF29;}
.cython.score-52 {background-color: #FFFF29;}
.cython.score-53 {background-color: #FFFF28;}
.cython.score-54 {background-color: #FFFF27;}
.cython.score-55 {background-color: #FFFF27;}
.cython.score-56 {background-color: #FFFF26;}
.cython.score-57 {background-color: #FFFF26;}
.cython.score-58 {background-color: #FFFF25;}
.cython.score-59 {background-color: #FFFF24;}
.cython.score-60 {background-color: #FFFF24;}
.cython.score-61 {background-color: #FFFF23;}
.cython.score-62 {background-color: #FFFF23;}
.cython.score-63 {background-color: #FFFF22;}
.cython.score-64 {background-color: #FFFF22;}
.cython.score-65 {background-color: #FFFF22;}
.cython.score-66 {background-color: #FFFF21;}
.cython.score-67 {background-color: #FFFF21;}
.cython.score-68 {background-color: #FFFF20;}
.cython.score-69 {background-color: #FFFF20;}
.cython.score-70 {background-color: #FFFF1f;}
.cython.score-71 {background-color: #FFFF1f;}
.cython.score-72 {background-color: #FFFF1f;}
.cython.score-73 {background-color: #FFFF1e;}
.cython.score-74 {background-color: #FFFF1e;}
.cython.score-75 {background-color: #FFFF1e;}
.cython.score-76 {background-color: #FFFF1d;}
.cython.score-77 {background-color: #FFFF1d;}
.cython.score-78 {background-color: #FFFF1c;}
.cython.score-79 {background-color: #FFFF1c;}
.cython.score-80 {background-color: #FFFF1c;}
.cython.score-81 {background-color: #FFFF1c;}
.cython.score-82 {background-color: #FFFF1b;}
.cython.score-83 {background-color: #FFFF1b;}
.cython.score-84 {background-color: #FFFF1b;}
.cython.score-85 {background-color: #FFFF1a;}
.cython.score-86 {background-color: #FFFF1a;}
.cython.score-87 {background-color: #FFFF1a;}
.cython.score-88 {background-color: #FFFF1a;}
.cython.score-89 {background-color: #FFFF19;}
.cython.score-90 {background-color: #FFFF19;}
.cython.score-91 {background-color: #FFFF19;}
.cython.score-92 {background-color: #FFFF19;}
.cython.score-93 {background-color: #FFFF18;}
.cython.score-94 {background-color: #FFFF18;}
.cython.score-95 {background-color: #FFFF18;}
.cython.score-96 {background-color: #FFFF18;}
.cython.score-97 {background-color: #FFFF17;}
.cython.score-98 {background-color: #FFFF17;}
.cython.score-99 {background-color: #FFFF17;}
.cython.score-100 {background-color: #FFFF17;}
.cython.score-101 {background-color: #FFFF16;}
.cython.score-102 {background-color: #FFFF16;}
.cython.score-103 {background-color: #FFFF16;}
.cython.score-104 {background-color: #FFFF16;}
.cython.score-105 {background-color: #FFFF16;}
.cython.score-106 {background-color: #FFFF15;}
.cython.score-107 {background-color: #FFFF15;}
.cython.score-108 {background-color: #FFFF15;}
.cython.score-109 {background-color: #FFFF15;}
.cython.score-110 {background-color: #FFFF15;}
.cython.score-111 {background-color: #FFFF15;}
.cython.score-112 {background-color: #FFFF14;}
.cython.score-113 {background-color: #FFFF14;}
.cython.score-114 {background-color: #FFFF14;}
.cython.score-115 {background-color: #FFFF14;}
.cython.score-116 {background-color: #FFFF14;}
.cython.score-117 {background-color: #FFFF14;}
.cython.score-118 {background-color: #FFFF13;}
.cython.score-119 {background-color: #FFFF13;}
.cython.score-120 {background-color: #FFFF13;}
.cython.score-121 {background-color: #FFFF13;}
.cython.score-122 {background-color: #FFFF13;}
.cython.score-123 {background-color: #FFFF13;}
.cython.score-124 {background-color: #FFFF13;}
.cython.score-125 {background-color: #FFFF12;}
.cython.score-126 {background-color: #FFFF12;}
.cython.score-127 {background-color: #FFFF12;}
.cython.score-128 {background-color: #FFFF12;}
.cython.score-129 {background-color: #FFFF12;}
.cython.score-130 {background-color: #FFFF12;}
.cython.score-131 {background-color: #FFFF12;}
.cython.score-132 {background-color: #FFFF11;}
.cython.score-133 {background-color: #FFFF11;}
.cython.score-134 {background-color: #FFFF11;}
.cython.score-135 {background-color: #FFFF11;}
.cython.score-136 {background-color: #FFFF11;}
.cython.score-137 {background-color: #FFFF11;}
.cython.score-138 {background-color: #FFFF11;}
.cython.score-139 {background-color: #FFFF11;}
.cython.score-140 {background-color: #FFFF11;}
.cython.score-141 {background-color: #FFFF10;}
.cython.score-142 {background-color: #FFFF10;}
.cython.score-143 {background-color: #FFFF10;}
.cython.score-144 {background-color: #FFFF10;}
.cython.score-145 {background-color: #FFFF10;}
.cython.score-146 {background-color: #FFFF10;}
.cython.score-147 {background-color: #FFFF10;}
.cython.score-148 {background-color: #FFFF10;}
.cython.score-149 {background-color: #FFFF10;}
.cython.score-150 {background-color: #FFFF0f;}
.cython.score-151 {background-color: #FFFF0f;}
.cython.score-152 {background-color: #FFFF0f;}
.cython.score-153 {background-color: #FFFF0f;}
.cython.score-154 {background-color: #FFFF0f;}
.cython.score-155 {background-color: #FFFF0f;}
.cython.score-156 {background-color: #FFFF0f;}
.cython.score-157 {background-color: #FFFF0f;}
.cython.score-158 {background-color: #FFFF0f;}
.cython.score-159 {background-color: #FFFF0f;}
.cython.score-160 {background-color: #FFFF0f;}
.cython.score-161 {background-color: #FFFF0e;}
.cython.score-162 {background-color: #FFFF0e;}
.cython.score-163 {background-color: #FFFF0e;}
.cython.score-164 {background-color: #FFFF0e;}
.cython.score-165 {background-color: #FFFF0e;}
.cython.score-166 {background-color: #FFFF0e;}
.cython.score-167 {background-color: #FFFF0e;}
.cython.score-168 {background-color: #FFFF0e;}
.cython.score-169 {background-color: #FFFF0e;}
.cython.score-170 {background-color: #FFFF0e;}
.cython.score-171 {background-color: #FFFF0e;}
.cython.score-172 {background-color: #FFFF0e;}
.cython.score-173 {background-color: #FFFF0d;}
.cython.score-174 {background-color: #FFFF0d;}
.cython.score-175 {background-color: #FFFF0d;}
.cython.score-176 {background-color: #FFFF0d;}
.cython.score-177 {background-color: #FFFF0d;}
.cython.score-178 {background-color: #FFFF0d;}
.cython.score-179 {background-color: #FFFF0d;}
.cython.score-180 {background-color: #FFFF0d;}
.cython.score-181 {background-color: #FFFF0d;}
.cython.score-182 {background-color: #FFFF0d;}
.cython.score-183 {background-color: #FFFF0d;}
.cython.score-184 {background-color: #FFFF0d;}
.cython.score-185 {background-color: #FFFF0d;}
.cython.score-186 {background-color: #FFFF0d;}
.cython.score-187 {background-color: #FFFF0c;}
.cython.score-188 {background-color: #FFFF0c;}
.cython.score-189 {background-color: #FFFF0c;}
.cython.score-190 {background-color: #FFFF0c;}
.cython.score-191 {background-color: #FFFF0c;}
.cython.score-192 {background-color: #FFFF0c;}
.cython.score-193 {background-color: #FFFF0c;}
.cython.score-194 {background-color: #FFFF0c;}
.cython.score-195 {background-color: #FFFF0c;}
.cython.score-196 {background-color: #FFFF0c;}
.cython.score-197 {background-color: #FFFF0c;}
.cython.score-198 {background-color: #FFFF0c;}
.cython.score-199 {background-color: #FFFF0c;}
.cython.score-200 {background-color: #FFFF0c;}
.cython.score-201 {background-color: #FFFF0c;}
.cython.score-202 {background-color: #FFFF0c;}
.cython.score-203 {background-color: #FFFF0b;}
.cython.score-204 {background-color: #FFFF0b;}
.cython.score-205 {background-color: #FFFF0b;}
.cython.score-206 {background-color: #FFFF0b;}
.cython.score-207 {background-color: #FFFF0b;}
.cython.score-208 {background-color: #FFFF0b;}
.cython.score-209 {background-color: #FFFF0b;}
.cython.score-210 {background-color: #FFFF0b;}
.cython.score-211 {background-color: #FFFF0b;}
.cython.score-212 {background-color: #FFFF0b;}
.cython.score-213 {background-color: #FFFF0b;}
.cython.score-214 {background-color: #FFFF0b;}
.cython.score-215 {background-color: #FFFF0b;}
.cython.score-216 {background-color: #FFFF0b;}
.cython.score-217 {background-color: #FFFF0b;}
.cython.score-218 {background-color: #FFFF0b;}
.cython.score-219 {background-color: #FFFF0b;}
.cython.score-220 {background-color: #FFFF0b;}
.cython.score-221 {background-color: #FFFF0b;}
.cython.score-222 {background-color: #FFFF0a;}
.cython.score-223 {background-color: #FFFF0a;}
.cython.score-224 {background-color: #FFFF0a;}
.cython.score-225 {background-color: #FFFF0a;}
.cython.score-226 {background-color: #FFFF0a;}
.cython.score-227 {background-color: #FFFF0a;}
.cython.score-228 {background-color: #FFFF0a;}
.cython.score-229 {background-color: #FFFF0a;}
.cython.score-230 {background-color: #FFFF0a;}
.cython.score-231 {background-color: #FFFF0a;}
.cython.score-232 {background-color: #FFFF0a;}
.cython.score-233 {background-color: #FFFF0a;}
.cython.score-234 {background-color: #FFFF0a;}
.cython.score-235 {background-color: #FFFF0a;}
.cython.score-236 {background-color: #FFFF0a;}
.cython.score-237 {background-color: #FFFF0a;}
.cython.score-238 {background-color: #FFFF0a;}
.cython.score-239 {background-color: #FFFF0a;}
.cython.score-240 {background-color: #FFFF0a;}
.cython.score-241 {background-color: #FFFF0a;}
.cython.score-242 {background-color: #FFFF0a;}
.cython.score-243 {background-color: #FFFF0a;}
.cython.score-244 {background-color: #FFFF0a;}
.cython.score-245 {background-color: #FFFF0a;}
.cython.score-246 {background-color: #FFFF09;}
.cython.score-247 {background-color: #FFFF09;}
.cython.score-248 {background-color: #FFFF09;}
.cython.score-249 {background-color: #FFFF09;}
.cython.score-250 {background-color: #FFFF09;}
.cython.score-251 {background-color: #FFFF09;}
.cython.score-252 {background-color: #FFFF09;}
.cython.score-253 {background-color: #FFFF09;}
.cython.score-254 {background-color: #FFFF09;}
</style>
</head>
<body class="cython">
<p><span style="border-bottom: solid 1px grey;">Generated by Cython 0.29b1</span></p>
<p>
<span style="background-color: #FFFF00">Yellow lines</span> hint at Python interaction.<br />
Click on a line that starts with a "<code>+</code>" to see the C code that Cython generated for it.
</p>
<p>Raw output: <a href="test.c">test.c</a></p>
<div class="cython"><pre class="cython line score-0">&#xA0;<span class="">001</span>: #cython: language_level = 3</pre>
<pre class="cython line score-0">&#xA0;<span class="">002</span>: from cython.parallel import parallel</pre>
<pre class="cython line score-0">&#xA0;<span class="">003</span>: from libc.stdio cimport printf</pre>
<pre class="cython line score-0">&#xA0;<span class="">004</span>: """</pre>
<pre class="cython line score-0">&#xA0;<span class="">005</span>: GOAL: implement nogil option in cdef class (extension types)</pre>
<pre class="cython line score-0">&#xA0;<span class="">006</span>: and native memory manager (refcount based) that does not</pre>
<pre class="cython line score-0">&#xA0;<span class="">007</span>: depend on cpython's memory manager and that does not require GIL.</pre>
<pre class="cython line score-0">&#xA0;<span class="">008</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">009</span>: HINT: look at C++ standard library (that works very nicely with Cython)</pre>
<pre class="cython line score-0">&#xA0;<span class="">010</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">011</span>: Cython documentation if here: http://docs.cython.org/en/latest/</pre>
<pre class="cython line score-0">&#xA0;<span class="">012</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">013</span>: Basic usage: http://docs.cython.org/en/latest/src/quickstart/build.html</pre>
<pre class="cython line score-0">&#xA0;<span class="">014</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">015</span>: Tutorial: http://docs.cython.org/en/latest/src/tutorial/cython_tutorial.html</pre>
<pre class="cython line score-0">&#xA0;<span class="">016</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">017</span>: Language: http://docs.cython.org/en/latest/src/userguide/language_basics.html</pre>
<pre class="cython line score-0">&#xA0;<span class="">018</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">019</span>: Extension types: http://docs.cython.org/en/latest/src/userguide/extension_types.html</pre>
<pre class="cython line score-0">&#xA0;<span class="">020</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">021</span>: Extension Types are the "pure cython" classes that I want to be able to</pre>
<pre class="cython line score-0">&#xA0;<span class="">022</span>: use without depending on cpython GIL (and in essence runtime, memory manager, etc.)</pre>
<pre class="cython line score-0">&#xA0;<span class="">023</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">024</span>: Cython memory allocation: http://docs.cython.org/en/latest/src/tutorial/memory_allocation.html</pre>
<pre class="cython line score-0">&#xA0;<span class="">025</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">026</span>: Parallelism: http://docs.cython.org/en/latest/src/userguide/parallelism.html</pre>
<pre class="cython line score-0">&#xA0;<span class="">027</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">028</span>: Explains how nogil is posisble in cython for anything that</pre>
<pre class="cython line score-0">&#xA0;<span class="">029</span>: only relies on C libraries that are multi-threaded</pre>
<pre class="cython line score-0">&#xA0;<span class="">030</span>: """</pre>
<pre class="cython line score-0">&#xA0;<span class="">031</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">032</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">033</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">034</span>: # cdef class SomeMemory:</pre>
<pre class="cython line score-0" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">035</span>: cdef class SomeMemory nogil:</pre>
<pre class='cython code score-0 '>struct __pyx_obj_4test_SomeMemory {
// nogil
size_t ob_refcnt;
struct __pyx_vtabstruct_4test_SomeMemory *__pyx_vtab;
double a;
double b;
};
struct __pyx_vtabstruct_4test_SomeMemory {
void (*foo)(struct __pyx_obj_4test_SomeMemory *);
};
static struct __pyx_vtabstruct_4test_SomeMemory *__pyx_vtabptr_4test_SomeMemory;
</pre><pre class="cython line score-0">&#xA0;<span class="">036</span>: """</pre>
<pre class="cython line score-0">&#xA0;<span class="">037</span>: This is a cdef class which is also called</pre>
<pre class="cython line score-0">&#xA0;<span class="">038</span>: a extensino type. It is a kind of C struct</pre>
<pre class="cython line score-0">&#xA0;<span class="">039</span>: that also acts as a python object.</pre>
<pre class="cython line score-0">&#xA0;<span class="">040</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">041</span>: We would like to be able to define "nogil"</pre>
<pre class="cython line score-0">&#xA0;<span class="">042</span>: extension types:</pre>
<pre class="cython line score-0">&#xA0;<span class="">043</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">044</span>: cdef class SomeMemory nogil:</pre>
<pre class="cython line score-0">&#xA0;<span class="">045</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">046</span>: where all methods are "nogil" and memory</pre>
<pre class="cython line score-0">&#xA0;<span class="">047</span>: allocation does not depend on python runtime</pre>
<pre class="cython line score-0">&#xA0;<span class="">048</span>: """</pre>
<pre class="cython line score-0">&#xA0;<span class="">049</span>: cdef double a;</pre>
<pre class="cython line score-0">&#xA0;<span class="">050</span>: cdef double b;</pre>
<pre class="cython line score-0">&#xA0;<span class="">051</span>: </pre>
<pre class="cython line score-0" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">052</span>: cdef void foo(self) nogil:</pre>
<pre class='cython code score-0 '>static void __pyx_f_4test_10SomeMemory_foo(struct __pyx_obj_4test_SomeMemory *__pyx_v_self) {
/* … */
/* function exit code */
}
</pre><pre class="cython line score-0">&#xA0;<span class="">053</span>: """</pre>
<pre class="cython line score-0">&#xA0;<span class="">054</span>: It is possible to define native C/Cython methods</pre>
<pre class="cython line score-0">&#xA0;<span class="">055</span>: that release the GIL (cool...)</pre>
<pre class="cython line score-0">&#xA0;<span class="">056</span>: """</pre>
<pre class="cython line score-0" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">057</span>: while 1:</pre>
<pre class='cython code score-0 '> while (1) {
</pre><pre class="cython line score-0" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">058</span>: self.a += 1</pre>
<pre class='cython code score-0 '> __pyx_v_self-&gt;a = (__pyx_v_self-&gt;a + 1.0);
}
</pre><pre class="cython line score-0">&#xA0;<span class="">059</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">060</span>: # Not allowed to define pure Python function in the extension type with nogil option now</pre>
<pre class="cython line score-0">&#xA0;<span class="">061</span>: # since we want this extension type is CPython free</pre>
<pre class="cython line score-0">&#xA0;<span class="">062</span>: # def baz(self):</pre>
<pre class="cython line score-0">&#xA0;<span class="">063</span>: # """</pre>
<pre class="cython line score-0">&#xA0;<span class="">064</span>: # It is also possible to define standard python</pre>
<pre class="cython line score-0">&#xA0;<span class="">065</span>: # methods</pre>
<pre class="cython line score-0">&#xA0;<span class="">066</span>: # """</pre>
<pre class="cython line score-0">&#xA0;<span class="">067</span>: # pass</pre>
<pre class="cython line score-0">&#xA0;<span class="">068</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">069</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">070</span>: # cdef bar(): # it is currently impossible to release GIL</pre>
<pre class="cython line score-0" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">071</span>: cdef double bar() nogil: # yet this is what we would like to</pre>
<pre class='cython code score-0 '>static double __pyx_f_4test_bar(void) {
struct __pyx_obj_4test_SomeMemory *__pyx_v_o1 = 0;
struct __pyx_obj_4test_SomeMemory *__pyx_v_o2 = 0;
double __pyx_r;
/* … */
/* function exit code */
__pyx_L0:;
return __pyx_r;
}
</pre><pre class="cython line score-0">&#xA0;<span class="">072</span>: """</pre>
<pre class="cython line score-0">&#xA0;<span class="">073</span>: This is a pure "cython method" which we would like to</pre>
<pre class="cython line score-0">&#xA0;<span class="">074</span>: be able to declare with nogil option but this requires</pre>
<pre class="cython line score-0">&#xA0;<span class="">075</span>: to first introduce the concept of nogil in cdef class</pre>
<pre class="cython line score-0">&#xA0;<span class="">076</span>: """</pre>
<pre class="cython line score-0">&#xA0;<span class="">077</span>: # cdef SomeMemory o = SomeMemory(42.0, 3.14) # for this we need class allocation to handle memory without libpython</pre>
<pre class="cython line score-0" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">078</span>: cdef SomeMemory o1 = SomeMemory(1, 1.0)</pre>
<pre class='cython code score-0 '> __pyx_t_1 = (struct __pyx_obj_4test_SomeMemory *)malloc(sizeof(struct __pyx_obj_4test_SomeMemory));
__pyx_t_1-&gt;a = 1.0;
__pyx_t_1-&gt;b = 1.0;
__pyx_v_o1 = __pyx_t_1;
</pre><pre class="cython line score-0" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">079</span>: cdef SomeMemory o2 = SomeMemory(2, 2.0)</pre>
<pre class='cython code score-0 '> __pyx_t_1 = (struct __pyx_obj_4test_SomeMemory *)malloc(sizeof(struct __pyx_obj_4test_SomeMemory));
__pyx_t_1-&gt;a = 2.0;
__pyx_t_1-&gt;b = 2.0;
__pyx_v_o2 = __pyx_t_1;
</pre><pre class="cython line score-4" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">080</span>: with nogil, parallel():</pre>
<pre class='cython code score-4 '> {
#ifdef WITH_THREAD
PyThreadState *_save;
Py_UNBLOCK_THREADS
<span class='pyx_c_api'>__Pyx_FastGIL_Remember</span>();
#endif
/*try:*/ {
{
#if ((defined(__APPLE__) || defined(__OSX__)) &amp;&amp; (defined(__GNUC__) &amp;&amp; (__GNUC__ &gt; 2 || (__GNUC__ == 2 &amp;&amp; (__GNUC_MINOR__ &gt; 95)))))
#undef likely
#undef unlikely
#define likely(x) (x)
#define unlikely(x) (x)
#endif
#ifdef _OPENMP
#pragma omp parallel
#endif /* _OPENMP */
{
/* … */
/*finally:*/ {
/*normal exit:*/{
#ifdef WITH_THREAD
<span class='pyx_c_api'>__Pyx_FastGIL_Forget</span>();
Py_BLOCK_THREADS
#endif
goto __pyx_L5;
}
__pyx_L5:;
}
}
</pre><pre class="cython line score-0" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">081</span>: o1.foo()</pre>
<pre class='cython code score-0 '> __pyx_f_4test_10SomeMemory_foo(__pyx_v_o1);
</pre><pre class="cython line score-0" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">082</span>: o2.foo()</pre>
<pre class='cython code score-0 '> __pyx_f_4test_10SomeMemory_foo(__pyx_v_o2);
}
}
#if ((defined(__APPLE__) || defined(__OSX__)) &amp;&amp; (defined(__GNUC__) &amp;&amp; (__GNUC__ &gt; 2 || (__GNUC__ == 2 &amp;&amp; (__GNUC_MINOR__ &gt; 95)))))
#undef likely
#undef unlikely
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif
}
</pre><pre class="cython line score-0">&#xA0;<span class="">083</span>: # o.foo() # and we need method selection to be independent of libpython</pre>
<pre class="cython line score-0">&#xA0;<span class="">084</span>: # o.foo1(2)</pre>
<pre class="cython line score-0">&#xA0;<span class="">085</span>: # o.a = 2.732</pre>
<pre class="cython line score-0">&#xA0;<span class="">086</span>: # o.fact(100)</pre>
<pre class="cython line score-0">&#xA0;<span class="">087</span>: </pre>
<pre class="cython line score-0" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">088</span>: return o1.a</pre>
<pre class='cython code score-0 '> __pyx_r = __pyx_v_o1-&gt;a;
goto __pyx_L0;
</pre><pre class="cython line score-0">&#xA0;<span class="">089</span>: </pre>
<pre class="cython line score-7" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">090</span>: cpdef baz():</pre>
<pre class='cython code score-7 '>static PyObject *__pyx_pw_4test_1baz(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_f_4test_baz(CYTHON_UNUSED int __pyx_skip_dispatch) {
PyObject *__pyx_r = NULL;
<span class='refnanny'>__Pyx_RefNannyDeclarations</span>
<span class='refnanny'>__Pyx_RefNannySetupContext</span>("baz", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
<span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1);
<span class='pyx_c_api'>__Pyx_AddTraceback</span>("test.baz", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
<span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r);
<span class='refnanny'>__Pyx_RefNannyFinishContext</span>();
return __pyx_r;
}
/* Python wrapper */
static PyObject *__pyx_pw_4test_1baz(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_4test_baz[] = "\n This method is both callable from python and pure \"cython\".\n It can call both cdef methods and usual python functions\n ";
static PyObject *__pyx_pw_4test_1baz(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
<span class='refnanny'>__Pyx_RefNannyDeclarations</span>
<span class='refnanny'>__Pyx_RefNannySetupContext</span>("baz (wrapper)", 0);
__pyx_r = __pyx_pf_4test_baz(__pyx_self);
/* function exit code */
<span class='refnanny'>__Pyx_RefNannyFinishContext</span>();
return __pyx_r;
}
static PyObject *__pyx_pf_4test_baz(CYTHON_UNUSED PyObject *__pyx_self) {
PyObject *__pyx_r = NULL;
<span class='refnanny'>__Pyx_RefNannyDeclarations</span>
<span class='refnanny'>__Pyx_RefNannySetupContext</span>("baz", 0);
<span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r);
__pyx_t_1 = __pyx_f_4test_baz(0);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error)</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
<span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1);
<span class='pyx_c_api'>__Pyx_AddTraceback</span>("test.baz", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
<span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r);
<span class='refnanny'>__Pyx_RefNannyFinishContext</span>();
return __pyx_r;
}
</pre><pre class="cython line score-0">&#xA0;<span class="">091</span>: """</pre>
<pre class="cython line score-0">&#xA0;<span class="">092</span>: This method is both callable from python and pure "cython".</pre>
<pre class="cython line score-0">&#xA0;<span class="">093</span>: It can call both cdef methods and usual python functions</pre>
<pre class="cython line score-0">&#xA0;<span class="">094</span>: """</pre>
<pre class="cython line score-6" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">095</span>: return bar()</pre>
<pre class='cython code score-6 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r);
__pyx_t_1 = <span class='py_c_api'>PyFloat_FromDouble</span>(__pyx_f_4test_bar());<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 95, __pyx_L1_error)</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
</pre><pre class="cython line score-0">&#xA0;<span class="">096</span>: </pre>
<pre class="cython line score-12" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">097</span>: def bag():</pre>
<pre class='cython code score-12 '>/* Python wrapper */
static PyObject *__pyx_pw_4test_3bag(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyMethodDef __pyx_mdef_4test_3bag = {"bag", (PyCFunction)__pyx_pw_4test_3bag, METH_NOARGS, 0};
static PyObject *__pyx_pw_4test_3bag(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
<span class='refnanny'>__Pyx_RefNannyDeclarations</span>
<span class='refnanny'>__Pyx_RefNannySetupContext</span>("bag (wrapper)", 0);
__pyx_r = __pyx_pf_4test_2bag(__pyx_self);
/* function exit code */
<span class='refnanny'>__Pyx_RefNannyFinishContext</span>();
return __pyx_r;
}
static PyObject *__pyx_pf_4test_2bag(CYTHON_UNUSED PyObject *__pyx_self) {
PyObject *__pyx_r = NULL;
<span class='refnanny'>__Pyx_RefNannyDeclarations</span>
<span class='refnanny'>__Pyx_RefNannySetupContext</span>("bag", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
<span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1);
<span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2);
<span class='pyx_c_api'>__Pyx_AddTraceback</span>("test.bag", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
<span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r);
<span class='refnanny'>__Pyx_RefNannyFinishContext</span>();
return __pyx_r;
}
/* … */
__pyx_t_1 = PyCFunction_NewEx(&amp;__pyx_mdef_4test_3bag, NULL, __pyx_n_s_test);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error)</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);
if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_bag, __pyx_t_1) &lt; 0) <span class='error_goto'>__PYX_ERR(0, 97, __pyx_L1_error)</span>
<span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;
/* … */
__pyx_codeobj_ = (PyObject*)<span class='pyx_c_api'>__Pyx_PyCode_New</span>(0, 0, 0, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_test_pyx, __pyx_n_s_bag, 97, __pyx_empty_bytes);<span class='error_goto'> if (unlikely(!__pyx_codeobj_)) __PYX_ERR(0, 97, __pyx_L1_error)</span>
</pre><pre class="cython line score-4" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">098</span>: return str(baz())</pre>
<pre class='cython code score-4 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r);
__pyx_t_1 = __pyx_f_4test_baz(0);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 98, __pyx_L1_error)</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);
__pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(((PyObject *)(&amp;PyUnicode_Type)), __pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 98, __pyx_L1_error)</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);
<span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
goto __pyx_L0;
</pre><pre class="cython line score-0">&#xA0;<span class="">099</span>: </pre>
<pre class="cython line score-0">&#xA0;<span class="">100</span>: # We call here a cpdef function, which calls a def function</pre>
<pre class="cython line score-0">&#xA0;<span class="">101</span>: # which then allocates cdef class SomeMemory</pre>
<pre class="cython line score-9" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">102</span>: print(bag())</pre>
<pre class='cython code score-9 '> <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_t_1, __pyx_n_s_bag);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 102, __pyx_L1_error)</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);
__pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_CallNoArg</span>(__pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __pyx_L1_error)</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);
<span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_builtin_print, __pyx_t_2);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 102, __pyx_L1_error)</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);
<span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;
<span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;
</pre><pre class="cython line score-3" onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<span class="">103</span>: print("done")</pre>
<pre class='cython code score-3 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_builtin_print, __pyx_tuple__2, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error)</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);
<span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;
</pre></div></body></html>
from distutils.core import setup from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize from Cython.Build import cythonize
ext_modules = [
Extension(
'test',
['test.pyx'],
extra_compile_args=['-fopenmp'],
extra_link_args=['-fopenmp'],
)
]
setup( setup(
ext_modules = cythonize("test.pyx") ext_modules = cythonize(ext_modules)
) )
#cython: language_level = 3 #cython: language_level = 3
from cython.parallel import parallel
from libc.stdio cimport printf from libc.stdio cimport printf
""" """
GOAL: implement nogil option in cdef class (extension types) GOAL: implement nogil option in cdef class (extension types)
...@@ -53,8 +54,8 @@ cdef class SomeMemory nogil: ...@@ -53,8 +54,8 @@ cdef class SomeMemory nogil:
It is possible to define native C/Cython methods It is possible to define native C/Cython methods
that release the GIL (cool...) that release the GIL (cool...)
""" """
pass while 1:
# self.a = self.b self.a += 1
# Not allowed to define pure Python function in the extension type with nogil option now # Not allowed to define pure Python function in the extension type with nogil option now
# since we want this extension type is CPython free # since we want this extension type is CPython free
...@@ -76,6 +77,7 @@ cdef double bar() nogil: # yet this is what we would like to ...@@ -76,6 +77,7 @@ cdef double bar() nogil: # yet this is what we would like to
# cdef SomeMemory o = SomeMemory(42.0, 3.14) # for this we need class allocation to handle memory without libpython # cdef SomeMemory o = SomeMemory(42.0, 3.14) # for this we need class allocation to handle memory without libpython
cdef SomeMemory o1 = SomeMemory(1, 1.0) cdef SomeMemory o1 = SomeMemory(1, 1.0)
cdef SomeMemory o2 = SomeMemory(2, 2.0) cdef SomeMemory o2 = SomeMemory(2, 2.0)
with nogil, parallel():
o1.foo() o1.foo()
o2.foo() o2.foo()
# o.foo() # and we need method selection to be independent of libpython # o.foo() # and we need method selection to be independent of libpython
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment