Fake mutex

Fake mutex

Hi, Does Cilk Plus support fake_mutex? I could not find it in the documentation or language specification. Thanks.

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

fake_mutex isn't part of the language. It's a feature of theCilk screen race detector, and shipped with the Cilk Plus SDK which you can download for free from http://software.intel.com/en-us/articles/intel-cilk-plus-software-development-kit/.

- Barry

Which header file should I import? My include directory does not have cilk/fake_lock.h. I'm usingcomposer_xe_2011_sp1.7.256. Thanks.Yod

First you need to install the Cilk Plus SDK as I stated in the previous reply. Then you can install cilktools/fake_mutex. Here's one of our test programs as an example:

#include 
#include 
#include 
#include 
#include 

int x;

void race(void)
{
    x = 0;
}

void lock_and_race (cilkscreen::fake_mutex *m)
{
    m->lock();
    race();
    m->unlock();
}

void test_bare_fake_lock(void)
{
    printf ("test_bare_fake_lock\n");

    cilkscreen::fake_mutex *m = cilkscreen::create_fake_mutex();
    cilk_spawn lock_and_race(m);
    cilk_spawn lock_and_race(m);
    cilk_spawn lock_and_race(m);
    cilk_spawn lock_and_race(m);
    cilk_sync;
    cilkscreen::destroy_fake_mutex(m);
}

void guard_and_race (cilkscreen::fake_mutex *m)
{
    cilkscreen::lock_guard guard(*m);

    race();
}

void test_guarded_fake_lock(void)
{
    printf ("test_guarded_fake_lock\n");
    cilkscreen::fake_mutex *m = cilkscreen::create_fake_mutex();
    cilk_spawn guard_and_race(m);
    cilk_spawn guard_and_race(m);
    cilk_spawn guard_and_race(m);
    cilk_spawn guard_and_race(m);
    cilk_sync;
    cilkscreen::destroy_fake_mutex(m);
}

int main (int argc, char *argv[])
{
     test_bare_fake_lock();
     test_guarded_fake_lock();
     printf("done\n");
     return 0;
}

- Barry

It works. Thanks.

Hello Barry,

When i try to compile this program (named mutex.cpp), i have the following errors :

$ icpc -pthread -o mutex mutex.cpp -lcilkrts
/home/amina/projet/cilkplus-install/include/cilktools/fake_mutex.h(62): error: argument of type "const char *" is incompatible with parameter of type "void *"
__cilkscreen_acquire_lock(&lock_val);
^

/home/amina/projet/cilkplus-install/include/cilktools/fake_mutex.h(71): error: argument of type "const char *" is incompatible with parameter of type "void *"
__cilkscreen_release_lock(&lock_val);
^

compilation aborted for mutex.cpp (code 2)

I attached the files : fake_mutex.h and cilkscreen.h.

But when i compile it with the command g++, it works fine (g++ -pthread -o mutex mutex.cpp -lcilkrts). (for notes : i use the gcc 4.7.0 version).

Have you a fix for this ?

Thank you,

This is a known problem in cilkscreen.h that is fixed in a future version of the tools. You can fix it your version by modifying the definition of __cilkscreen_metacall in your copy:

/*
 * Cilkscreen "functions".  These macros generate metadata in your application
 * to notify Cilkscreen of program state changes
 */

#if ! defined(CILK_STUB) && defined(__INTEL_COMPILER)
#  define __cilkscreen_metacall(annotation,expr) \
    __notify_intrinsic((char *)annotation,expr)
#else
#  define __cilkscreen_metacall(annotation,expr) (annotation, (void) (expr))
#endif

- Barry

Thank you Barry, it works fine :)

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen