__cilkrts_param_set bug

__cilkrts_param_set bug

__cilkrts_param_set return 4(/**< Too late to change parameter value *).
Reinitialization of the library can not be completed, cause __cilkrts_end_cilk return "Attempt to shut down Cilk while Cilk is still runningAborted"

5 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Best Reply

I'm not exactly sure what the issue is here. What exactly are you passing to __cilkrts_set_param()?

To call __cilkrts_end_cilk(), You must have exited the function that contains the cilk_spawn. Consider the basic "fib" application:

int fib(int n)
{
    int x, y;
    if (n < 2)
        return n;
    x = cilk_spawn fib(n-1);
    y = fib(n-2);
    cilk_sync;
    return x+y;
}

int main(int argc, char **argv)
{
    int n = 30;
    printf ("fib(%d) = %d\n", n fib(n));
}

You can call __cilkrts_end_cilk() in main() because you've exited all functions containing a cilk_spawn. If main() was modified to spawn fib(n), then __cilkrts_end_cilk() would return an error.

- Barry

ok. i missed that. I wrote a wrapper function.
void wrapper_workerbody()
{
for(int i = 0; i < workers; i++) {
cilk_spawn workerbody();
}
cilk_sync;
}
and call it from main.
but __cilkrts_end_cilk() in main still aborted program with "Attempt to shut down Cilk while Cilk is still runningAborted". (CILK_NWORKERS is unset)

The following program works as expected:

#include 
#include 
#include 

int fib(int n)
{
    int x,y;
    if (n < 2)
        return n;
    x = cilk_spawn fib(n-1);
    y = fib(n-2);
    cilk_sync;
    return x+y;
}

int main(int argc, char **argv)
{
    int n = 30;
    int result;
    int err;

    err = __cilkrts_set_param("nworkers", "13");
    printf("__cilkrts_set_param("nworkers", "13") returned %d\n", err);

#ifdef SPAWN_IN_MAIN
    result = cilk_spawn fib(n);
    cilk_sync;
#else
    result = fib(n);
#endif

    printf("fib(%d)=%d\n", n, result);

    __cilkrts_end_cilk();

    return 0;
}


If I compile it with SPAWN_IN_MAIN defined, __cilkrts_end_cilk() prints the message "Attempt to shut down Cilk while Cilk is still running". If I compile it without defining SPAWN_IN_MAIN, it completes normally.

If you can give me a program that's misbehaving, I'll take a look at it.

- Barry

thx, i've fixed program.

Melden Sie sich an, um einen Kommentar zu hinterlassen.