On 4 May 2011 13:54, Dag Sverre Seljebotn <d.s.seljeb...@astro.uio.no> wrote: > On 05/04/2011 01:48 PM, mark florisson wrote: >> >> On 4 May 2011 13:47, mark florisson<markflorisso...@gmail.com> wrote: >>> >>> On 4 May 2011 13:45, Dag Sverre Seljebotn<d.s.seljeb...@astro.uio.no> >>> wrote: > >>>> Look. >>>> >>>> i = 42 >>>> for i in prange(n): >>>> f(i) >>>> print i # want 42 whenever n == 0 >>>> >>>> Now, translate this to: >>>> >>>> i = 42; >>>> #pragma omp parallel for firstprivate(i) lastprivate(i) >>>> for (temp = 0; ...; ...) { >>>> i = ... >>>> } >>>> #pragma omp parallel end >>>> /* At this point, i == 42 if n == 0 */ >>>> >>>> Am I missing something? >>> >>> Yes, 'i' may be uninitialized with nsteps> 0 (this should be valid >>> code). So if nsteps> 0, we need to initialize 'i' to something to get >>> correct behaviour with firstprivate. > > This I don't see. I think I need to be spoon-fed on this one.
So assume this code cdef int i for i in prange(10): ... Now if we transform this without the guard we get int i; #pragma omp parallel for firstprivate(i) lastprivate(i) for (...) { ...} This is invalid C code, but valid Cython code. So we need to initialize 'i', but then we get our "leave it unaffected for 0 iterations" paradox. So we need a guard. >> And of course, if you initialize 'i' unconditionally, you change 'i' >> whereas you might have to leave it unaffected. > > This I see. > > Dag Sverre > _______________________________________________ > cython-devel mailing list > cython-devel@python.org > http://mail.python.org/mailman/listinfo/cython-devel > _______________________________________________ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel