Question

I am trying to call a function inside a parallel for loop in Cilk plus. If I declare an array in the function that I call, would it have race issues? I am getting Segmentation fault or Aborted(Core dumped) errors after some runs of the loop.

PScan()
{
    // Would working on w create race issues?
    double *w = calloc(num,sizeof(double));
}
Was it helpful?

Solution

If PScan() is called from a cilk_for loop, then using the w array will not be a race. All parallel strands will have their own allocated copy of w. Be sure to free that memory when you're done with it.

However, be aware that calling memory allocation routines like calloc may involve locks which can limit performance. Alternate memory allocators like tbbmalloc can mitigate this.

You can use the Cilkscreen tool to search for races. The Cilk Tools (The Cilkscreen race detector and the Cilkview scalability analyzer) are available for free from http://cilkplus.org/download

- Barry Tannenbaum
  Intel Cilk Plus Runtime Development
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top