c++ - Error with openmp for Nested for-loop -
i have used eigen library in object oriented cpp code. defined main object, 2dgf, , in methods of it, have used openmp. want use openmp in method following:
#pragma omp parallel num_threads(non) #pragma omp for(unsigned int ie=0;ie<ne;ie++){ for(unsigned int ik=0;ik<nk;ik++){ for(unsigned int ii=0; ii<nl ;ii++){ for(unsigned int jj=0; jj<nl ;jj++){ if(abs(coorx[ii]-coorx[jj])<dioglim){ g.insert(ie*nl+ii,ik*nl+jj)=0; gr.insert(ie*nl+ii,ik*nl+jj)=0; s.insert(ie*nl+ii,ik*nl+jj)=0; sr.insert(ie*nl+ii,ik*nl+jj)=0; } } } } }
where g, gr, s , sr sparse matrices. without using openmp works no problem. when use openmp, receive following error:
2dgf : malloc.c:2372: sysmalloc: assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 *(sizeof(size_t))) - 1)) & ~((2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long) old_end & pagemask) == 0)' failed.
aborted (core dumped)
may me fix it?
i don't know eigen. read bit in documentation method insert() of sparsematrix says reserving room
other inserts. did reserve enough space inserts?
if not, same bug present in following code.
#include <iostream> #include <vector> #include <omp.h> int main() { std::vector< int > vints; #pragma omp parallel (int = 0; < 1000; i++) { vints.push_back( ); } return 0; }
this might end in segmentation fault. reason vector relocated different region int memory. can avoided reserving enough memory vector. in case vints.reserve(1000)
.
sparsematrix offers reserve method. try this, @ least rule out possible bug.
edit: here code for-loops , simple assignment in innermost loop. program compiles g++ -fopenmp -wall -werror main.cpp
without error or warnings. program executes ouput i=99.
#include <iostream> #include <omp.h> #include <vector> #define non 3 int main() { int = 0; unsigned int ne = 100; unsigned int nk = 100; unsigned int nl = 100; #pragma omp parallel num_threads(non) #pragma omp for(unsigned int ie=0;ie<ne;ie++){ for(unsigned int ik=0;ik<nk;ik++){ for(unsigned int ii=0; ii<nl ;ii++){ for(unsigned int jj=0; jj<nl ;jj++){ = jj; } } } } return 0; }
Comments
Post a Comment