0

I'm trying to use openmp to run the below code, but I get Segmentation Fault

void modKeyGenPrs(mat_GF2E *&Prs, mat_GF2E Lst[], mat_GF2E L1, mat_GF2E L2) {
    Prs = new mat_GF2E[m];
    mat_GF2E L1_trans = transpose(L1);
        #pragma omp parallel shared(L1_trans,L2,Lst,Prs,L1) 
        {
               #pragma omp for
               for (int i = 0; i < m; i++) {
                   (Prs[i]).SetDims(n, n);
                   for (int j = 0; j < m; j++) {
                       Prs[i] = Prs[i] + (L2[i][j] * (L1_trans * (Lst[i]) * L1));
                   }
               }
       }
} 
user46060
  • 123
  • 1
  • 10
  • are you sure you wish to use "#pragma omp parallel for" inside a parallel region; just use "#pragma omp for" – arbitUser1401 Jun 25 '14 at 17:17
  • Try to run it in a debugger. Also, you got nested parallelism; use `#pragma omp for` within a parallel region, or use `#pragma omp parallel for` without an outer `#pragma omp parallel`. – Sedenion Jun 25 '14 at 17:23
  • I edit my code with your suggestion by I get the same error, I use a debugger and I obtain No source available for "NTL::mul() at 0x7ffff7a6ba0d – user46060 Jun 25 '14 at 17:41
  • Use the debugger to get the stack trace and therefore the position in your code where the program breaks. Your error message indicates that you use NTL incorrectly (because it stops in a library function). "No source" means that, well, the debugger can't find the source-code of the library. Also, does the program run fine without OpenMP? – Sedenion Jun 25 '14 at 17:52
  • @Gugi without OpenMP the program works, about NTL I think that my debugger need NTL configuration. – user46060 Jun 25 '14 at 17:55
  • @user46060 If you use gdb as a debugger, look at the backtrace (`bt`) after the program crashes. This will print the stack of called functions. Look for the first function in that list that **you** coded (probably `modKeyGenPrs`), and the associated line-number. This is the location where the program breaks. To get any meaning full output, you need to compile your program with debug-symbols (`-g` for g++). For a quick tutorial, see http://www.cs.cmu.edu/~gilpin/tutorial/ . On another note, I hope you turned on warnings (`-Wall -Wextra` for g++)? – Sedenion Jun 26 '14 at 08:39
  • The error address is close to the negative addresses boundary and is probably somewhere in the stack of the main thread. Therefore you might be running out of stack space. Increase the stack of the main thread with `ulimit -a unlimited` and the stack size of the worker threads with `export OMP_STACKSIZE=16M` (this sets the stack size to 16 MiB but you might need more). – Hristo Iliev Jun 26 '14 at 09:57
  • Are you sure you compiled NTL theadsave? – AbcAeffchen May 07 '16 at 11:58

0 Answers0