> -----Original Message----- > From: Jakub Jelinek [mailto:ja...@redhat.com] > Sent: Tuesday, December 3, 2013 8:40 AM > To: Iyer, Balaji V > Cc: Jeff Law; Jason Merrill; Aldy Hernandez; gcc-patches@gcc.gnu.org; > r...@redhat.com > Subject: Re: [PATCH] _Cilk_for for C and C++ > > On Tue, Dec 03, 2013 at 01:25:57PM +0000, Iyer, Balaji V wrote: > > > >> As you can tell, this is not how openmp handles a #pragma omp for > loop. > > > > > > > > It's different in detail, but #pragma omp parallel for works very > > > > similarly: it creates a separate function for the body of the loop > > > > and then passes that to GOMP_parallel along with any shared data. > > > My thoughts exactly. > > > > I understand you both now. Let me look into the OMP routines and see > > what it is doing and see how I can port it to _Cilk_for. > > Yeah. The work is actually multi-stage, first during gimplification the code > does determine what variables are used in the #pragma omp parallel (etc., in > your case _Cilk_for) region, and whether they should be shared, or > privatized (and in that case in what way, normal private, firstprivate, > lastprivate, firstprivate+lastprivate, reduction, ...). Then there is > omplower > pass (already enabled for Cilk+ due to #pragma simd) that e.g. > lowers accesses to shared variables, creates new VAR_DECLs for the > privatized vars etc. and then ompexp pass that will create the outlined body > of the function and create call to the runtime library. > I have no idea what privatization behavior _Cilk_for wants, I'd expect that at > least the IV must be privatized, otherwise it would be racy, but about other > vars? >
In Cilk_for you don't need to privatize any variables. I need to pass in the loop_count, the grain (if the user specifies one), the nested function and its context to a Cilk specific function:__cilkrts_cilk_for_64 (or 32). The nested function has the body of the _Cilk_for and it has 3 parameter, context, start and end, where the start and end are passed in by the runtime which will tell what parts of the loop to execute. This thread has an example: http://gcc.gnu.org/ml/gcc-patches/2013-11/msg03567.html Thanks, Balaji V. Iyer. > Jakub