Implicit cilk_sync before try-block does not seem to work

Implicit cilk_sync before try-block does not seem to work

Hi,i wanted to implement an example from the Cilk Plus User Guide: Page 37, Exception Handling, where they show, how the implicit sync in front of a try-block could limit the parallelism of the program. My code is as follows:

void mysleep(int a) {

        sleep(a);

}
int main(int argc, char ** argv) {

        cilk_spawn mysleep(5);

        try {

                cilk_spawn mysleep(5);

                mysleep(5);

        }
        catch(int err) {

        }

}

In my understanding, this should take 10 seconds, as the first spawn of mysleep() has to be completed before the try block can execute.However, the program runs for 5 seconds, as if sleep would run in parallel all the time. I read in a post ofBalaji Iyer (Intel)that exception support was not fully implemented in GCC. Is that one of those cases were the support is missing?What i wanted to find out is the following: If you nest your cilk-keywords inside another function and you call that, there would be no implicit sync at the beginning of the try-block, as there are (lexically) no cilk-keywords (this is stated in the Cilk User Guide).But if you compile with gcc -O3 flag, gcc tries to create inline functions - that way the cilk-keyword would be back in the try-block and thus there would be a implicit sync. So if you are not careful, you may limit your parallelism without noticing it. Does anyone know if this is the case?

11 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hello

Im having some troubles too with exceptions that has something to do with implicit syncs.

My code looks like this

for( int i = 0 ; i < k ; i++ ) {
      cilk_for( unsgined int j = 0 ; j < p ; j++ ) {
          CILK_TRY {

               //do something that might throw
                  CILK_TRY {

                   //do something here

                   //there is a cilk_for in here but inside another function which is called

                   }

                   catch( something ) {  }

          }

          catch( something ) {}

    }


Even if i change CILK_TRY with try i get these errors

Race condition on location 0x7f0a870fb720
write access at 0x7f0a87c7bfe8: (__cxa_end_catch+0x78)
write access at 0x7f0a87c7bf4a: (__cxa_begin_catch+0x4a)
called by 0x7f0a881649af: (__cilk_spawn_006+0x7f)
called by 0x7f0a88164cb6: (cilk_for_recursive+0x286)
called by 0x7f0a8816510c: (cilk_for_root+0x2ec)
called by 0x401805: (main+0xc0)

Race condition on location 0x7f0a870fb720
read access at 0x7f0a87c7bf79: (__cxa_end_catch+0x9)
write access at 0x7f0a87c7bf4a: (__cxa_begin_catch+0x4a)
called by 0x7f0a881649af: (__cilk_spawn_006+0x7f)
called by 0x7f0a88164cb6: (cilk_for_recursive+0x286)
called by 0x7f0a8816510c: (cilk_for_root+0x2ec)
called by 0x401805: (main+0xc0)

Any ideas why this is happening?

I was wondering if this has something to do with the discarded exceptions.

Thanks

Attachments: 

AttachmentSize
Download test.cpp490 bytes

Hello Giannhssdra,
I was not able to reproduce yourresults. Itried the test code in my ubuntu machine (both 64 and 32 bit flavors) and I got the following output. Are you using the latest GCC? If not, please update your SVN directory and try again. Also, please let us know the flags you are using to compile your code.

Thanks,

Balaji V. Iyer.

$:~/b-gcc-test/gcc$ ../../install-test/bin/g++ test.cpp -lcilkrts -fcilkplus -O1

$:~/b-gcc-test/gcc$ ./a.out

start of main...

caught exc

skata

skata

caght char

skata

skata

end of main

$:~/b-gcc-test/gcc$ ../../install-test/bin/g++ test.cpp -lcilkrts -fcilkplus -O2

$:~/b-gcc-test/gcc$ ./a.out

start of main...

caught exc

skata

skata

caght char

skata

skata

end of main

$:~/b-gcc-test/gcc$ ../../install-test/bin/g++ test.cpp -lcilkrts -fcilkplus -O3

$:~/b-gcc-test/gcc$ ./a.out

start of main...

caught exc

skata

skata

caght char

skata

skata

end of main

$:~/b-gcc-test/gcc$ ../../install-test/bin/g++ test.cpp -lcilkrts -fcilkplus

$:~/b-gcc-test/gcc$ ./a.out

start of main...

caught exc

skata

skata

caght char

skata

skata

end of main

$:~/b-gcc-test/gcc$ ../../install-test/bin/g++ test.cpp -lcilkrts -fcilkplus -g

$:~/b-gcc-test/gcc$ ./a.out

start of main...

caught exc

skata

skata

caght char

skata

skata

end of main

$:~/b-gcc-test/gcc$

Hello Leifblaese,
Thank for pointing this out. I have tracked this bug, and willsend outa fixpatch soon. Can I pleaseuse the code that you have attached as part of the Cilk Plus GCC testsuite?

Thanks,

Balaji V. Iyer.

Hey,thanks, and sure, go ahead, i'm glad you can use it.leif

Hello Leif,
This patch should fix your problem: http://gcc.gnu.org/ml/gcc-patches/2012-08/msg00657.html. It is already checked into the branch.

Thanks,

Balaji V. Iyer.

Thanks for the answer.

I installed cilkplus a month ago in my ubuntu 64bit.Is there a newer version that i should install?
I compiled with these options : g++ -Wall -g -O1 -lcilkrts -ldl test.cpp -o test
You mentioned an -fcilkplus flag which is unrecognized flag for my compiler.

Also you said to update my svn directory.You mean to reinstall cilkplus?

The errors im getting are not from compilation or from running the program.Cilkscreeen gives these race contitions.
I found that the problem occurs with nested try blocks.

cilkfor( unsigned int i = 0 ; i < k ; i++ ) {
    try {

    throw 1;
     try  {

         throw 'a';

     }

     catch( char ) {}
   }

   catch( int ) {}

 }
if one of the try blocks doesnt throw cilkscreen gives no errors.But if both try blocks throw an exception then i get several race contitions like the one i mentioned before.My program doesnt crash or giving wrong results( its runs as expected ) but cilkscreen gives race contitions.

Can you explain to me what is this new patch and how can i use it?

Thanks

Hello Giannhssdra,
Cilk Plus GCC is an on-going project so we regularly update it with bug-fixes and adding missing features etc. So, it is generally a good idea to update it when you find a certain flags or features are not working (or working correctly). If you are using SVN, the best way to do it is to type "svn update" in your source directory. Please make sure to reconfigure in the build directory anddo "make" and "make install" again.

Thanks,

Balaji V. Iyer.

Ok thanks for the answer

I will reinstall it and let you know

Hello again

I reinstalled cilkplus as you said but now im having problems with cilkscreen and cilk_for.
Everything with compilation is ok.I added -fcilkplus in every file that i use cilk_for.

But when i use cilkscreen to check my program for race conditions every time i have a cilk_for cilkscreen just waits for something and never finishes.Its like that a spawned child from cilk_for never gets synced and cilkscreen waits for this child.

If i use for and spawn its iteration everything is ok and cilkscreen works fine.But if i change to cilk_for (without spawn inside)the program runs but cilkscreen never finishes.I stop cilkscreen with CTRL+ C but one core is still occupied and working 100%(maybe one child that was never synced)

My program runs with no errors but i cant use cilkscreen anymore

Can you check this file with cilkscreen and let me know for the results?
I compiled with these flags : g++ -Wall -g test.cpp -fcilkplus -lcilkrts -o test

Thanks

Attachments: 

AttachmentSize
Download test.cpp510 bytes

Hello Giannhssdra,
We have not fully implemented all the C++ exceptions support in Cilk Plus GCC. Can you please tell me a bit high-level detail about the project you are working on and how you are using exceptions? If you prefer to speak about this by email, please feel free to do so.

Thanks,

Balaji V. Iyer.

Login to leave a comment.