문제

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));
}
도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top