Software Archive
Read-only legacy content
17061 Discussions

simple cilk_spawn Segmentation Fault

Chris_Szalwinski
New Contributor I
552 Views

I'm having difficulty running a simple test case using cilk_spawn.  I'm compiling under gcc 4.9.0 20130520.

The following fib2010.cpp example, executes in 0.028s without cilk and takes 0.376s with cilk as long as I set the number of workers to 1.  If I change the number of workers to any number greater than one, I get a segmentation fault.

// fib2010.1.cpp
//

#include <iostream>
#include <cilk/cilk.h>
#include <cilk/cilk_api.h>

int fib(int n)
{
    if (n < 2)
        return n;

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

int main(int argc, char* argv[])
{
    std::cout << "No of workers = " << __cilkrts_get_nworkers() << std::endl;
    int n = 32;
    std::cout << "fib(" << n << ") = " << fib(n) << std::endl;
}

 

The hardware is Dual Core AMD Opteron 8220.

0 Kudos
1 Reply
Barry_T_Intel
Employee
552 Views

I'm having difficulty running a simple test case using cilk_spawn.  I'm compiling under gcc 4.9.0 20130520

That looks like an ancient compiler. I just tried it with a current version (pulled 20-Mar) without any problem:

[bash]$ g++ -fcilkplus -lcilkrts -o fib fib.cpp

$ ./fib

fib(32) = 3524578 - calculated using 8 workers

$ g++ --version

g++ (GCC) 4.9.0 20140320 (experimental)

Copyright (C) 2014 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$[/bash]

   - Barry

0 Kudos
Reply