I am trying to make use of prange
to run my loop in parallel.
I am using nested prange
. But during debugging I get not desired results.
This is my code:
%%cython
# distutils: language = c++
# distutils: extra_compile_args = -fopenmp
# distutils: extra_link_args = -fopenmp
cimport cython.parallel as parallel
from libcpp.vector cimport vector
cdef int current_row, current_col
cdef int current_thread_id
cdef vector[int] container_1
cdef vector[int] container_2
for current_row in parallel.prange(1000, num_threads=10, nogil=True):
for current_col in parallel.prange(1000, num_threads=10):
current_thread_id = parallel.threadid()
if current_thread_id == 4:
container_1.push_back(current_row)
container_2.push_back(current_col)
print container_1[0], ' ', container_2[0]
print container_1.back(), ' ', container_2.back()
This is what I get on the output:
400 0
499 999
As I see the inner loop is always executed fully for each thread.
Is it possible to make the nested prange
s to work?
And if yes, how can I track the outer thread id and inner thread id?