This will produce contiguous memory accesses (at least to new) which helps the serial case but especially the parallel case to avoid false sharing.Īnd finally, if you like to keep your sanity: drop the macros. It's also safe for new to be shared, because each iteration (and thus thread) accesses a separate element.įor performance reasons you should revert the order of the loops. The contents of private (and firstprivate) variables are not preserved after a parallel region. new is the result of the parallel region and should thus also be shared. If something is only read during the parallel region, which is the case for univ, w, h, then it can safely and should be shared. You most likely do not want to use firstprivate on all those variables, but shared instead. That said there are some other issues in your code. Alternatively you can use something other than a variably modified. I suppose you got to drop the default(none). #pragma omp parallel shared(a) default(none)įeel free to report a bug, or I will do so. Ī shorter version to reproduce: void foo(int n, int a) In a sense the compiler thinks about this code like: // instead of unsigned (*univ). What I suspect happens here is that the variably modified (pointer to variable length array) type uses a hidden variable w.13 that is implicitly accessed whenever univ is accessed. I think this is a bug in gcc, and it's still present in the latest version (7.2). Does anybody know why my code isn't compiling? Obviously, I do not have a variable called w.13, and that isn't some external variable that I am using. If I remove the default(none), the code compiles, but I want to keep it so that when I continue changing the code, the compiler would alert me if I forget to declare some variables private or firstprivate. Gameoflife.c:126:10: error: enclosing parallel Gameoflife.c:131:13: error: ‘w.13’ not specified in enclosing parallel ![]() I am compiling it with gcc-4.8 gameoflife.c -o gameoflife -std=gnu99 -O3 -fopenmp, on bash on Windows 10, and gcc gives me the following error: gameoflife.c: In function ‘evolve_parallel’: My macros (at the top of the file) are: #define for_x for (int x = 0 x < w x++) #pragma omp parallel for firstprivate(univ, new, w, h), collapse(2), default(none) I have the following function: void evolve_parallel(void *u, int w, int h) ![]() I am trying to use OpenMP to parallelize a simple program simulating Game of Life.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |