- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have to coordinate access to write on file from multiple concurrent workers.
So, i use the fake mutex class, but it doesn't work. the file is not correctly wrinting (workers interrupt to write).
cilkscreen::fake_mutex *a = cilkscreen::create_fake_mutex();
a->lock();
gpfgout->printSet(vars.gnprefix_len(), vars.gpprefix_itemset(), nsupport);
a->unlock();
cilkscreen::destroy_fake_mutex(a);
Is it correct to use fake mutex class to write on file ? or there is another class that allows writng on file ?
Thank you in advance,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to be linking against libtbb.so.
Here's the command I use to build this application on Linux:
icpc -I /home/nsl/bmtannen/project/cilkdev/linux/eng/cilkrts/unix-build/include \ -I /home/nsl/bmtannen/project/cilkdev/linux/eng/cilkrts/unix-build/../include \ -I /home/nsl/bmtannen/project/cilkdev/linux/tbb30_20110427oss/include \ -D TBB_USE_THREADING_TOOLS=1 -L /home/nsl/bmtannen/project/cilkdev/linux/eng/cilkrts/unix-build/linux64/lib -lcilkrts -L /home/nsl/bmtannen/project/cilkdev/linux/tbb30_20110427oss/build/linux_intel64_gcc_cc4.5.2_libc2.13_kernel2.6.38_debug \ -ltbb_debug \ -o tbb-test tbb-test.cpp
I've pulled down the TBB sources and built them myself.Your path the the TBB librarywill be different. You also probably don't need to specify the directory for the Cilk runtime.
TBB_USE_THREADING_TOOLS needs to be defined to make sure that the notifications that Cilkscreen uses will be present.
- Barry
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The fake_mutex class isn't intended to be real mutexes. They're... fake. They only signal the Cilkscreen race detector that a race is benign and can be ignored.
From the fake_mutex.h header file:
* Cilkscreen fake mutexes are provided to indicate to the Cilkscreen race * detector that a race should be ignored.
To coordinate between multiple workers or threads, you need to use "real" mutexes.You should look at the mutexes supplied by the OS you're running on (mutex on Linux, CRITICAL_SECTION on Windows). You can use cilkscreen::lock_guard with these if you wrap them in a class which provides the same methods as cilkscreen::fake_mutex.
You should also look at the OS-independent mutexes provided by TBB.
- Barry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've modified fake_mutex.h to make it clearer that this class does not provide mutual exclusion.
Also, if you're attempting to write to a file from multiple strands, you might want to look at reducer_ostream, which is intended for exactly this situation
- Barry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If fake mutex class does not provide mutual exclusion, so could you please show me an example to illustrate how can i use the TBB mutexes to lock/unlock sections (mutual exclusion) ?
I found the follwing example :
#includeIf this example (cilkMutex.cpp) uses correctly TBB mutex, it doesn't compile, i have this error :
#include
#include
int main()
{
tbb::mutex mut;
int sum = 0;
cilk_for (int i=0; i<10; ++i)
{
mut.lock();
sum = sum + i; // PROTECTED WITH LOCK
mut.unlock();
}
std::cout << "Sum is " << sum << std::endl;
return 0;
}
amina@amina-laptop:~/projet/cilkplus-install/examples/test$ icpc -pthread -o cilkMutex cilkMutex.cpp -lcilkrts
/tmp/icpcyhnUVY.o: In function `main':
cilkMutex.cpp:(.text+0x12c): undefined reference to `tbb::internal::handle_perror(int, char const*)'
Have you an idea for this problem ?
Thanks in advance,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here's one example:
#include#include #include #include tbb::spin_rw_mutex countMutex; int foo() { int z=0; cilk_for (int i = 0; i < 10; i++) { tbb::spin_rw_mutex::scoped_lock lock(countMutex); z *= i; } return z; } int main() { foo(); return 0; }
Note that support for TBB spinlocks required additional support in Cilkscreen. I confess I'm not sure if we've released that version yet. TBB locks that use OS mutexes should be fine.
- Barry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have the following error when compiling your example code :
amina@amina-laptop:~/projet/cilkplus-install/examples/test$ icpc -pthread -o cilkMutex cilkMutex.cpp -lcilkrts
/tmp/icpcMfVTwe.o: In function `__$U0':
cilkMutex.cpp:(.text+0xe8): undefined reference to `tbb::spin_rw_mutex_v3::internal_acquire_writer()'
have you an idea for this error ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to be linking against libtbb.so.
Here's the command I use to build this application on Linux:
icpc -I /home/nsl/bmtannen/project/cilkdev/linux/eng/cilkrts/unix-build/include \ -I /home/nsl/bmtannen/project/cilkdev/linux/eng/cilkrts/unix-build/../include \ -I /home/nsl/bmtannen/project/cilkdev/linux/tbb30_20110427oss/include \ -D TBB_USE_THREADING_TOOLS=1 -L /home/nsl/bmtannen/project/cilkdev/linux/eng/cilkrts/unix-build/linux64/lib -lcilkrts -L /home/nsl/bmtannen/project/cilkdev/linux/tbb30_20110427oss/build/linux_intel64_gcc_cc4.5.2_libc2.13_kernel2.6.38_debug \ -ltbb_debug \ -o tbb-test tbb-test.cpp
I've pulled down the TBB sources and built them myself.Your path the the TBB librarywill be different. You also probably don't need to specify the directory for the Cilk runtime.
TBB_USE_THREADING_TOOLS needs to be defined to make sure that the notifications that Cilkscreen uses will be present.
- Barry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It works fine, i use this command :
icpc -D TBB_USE_THREADING_TOOLS=1 -L /home/amina/Bureau/sourcesTBB/tbb30/build/linux_ia32_gcc_cc4.4.3_libc2.11.1_kernel2.6.32_debug/ -ltbb_debug -o TBB TBB.cpp -pthread -lcilkrts
To lock sections, i use the follwing code inside the loop for :
myMutex::scoped_lock lock;
lock.acquire(sm);
z *= i;
lock.release();
Thank you,
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page