I have a problem when using OpenMP in combination with firstprivate and std :: vector on an Intel C ++ compiler. Take the following three functions:
#include <omp.h> void pass_vector_by_value(std::vector<double> p) { #pragma omp parallel { //do sth } } void pass_vector_by_value_and_use_firstprivate(std::vector<double> p) { #pragma omp parallel firstprivate(p) { //do sth } } void create_vector_locally_and_use_firstprivate() { std::vector<double> p(3, 7); #pragma omp parallel firstprivate(p) { //do sth } }
The code compiles without warning:
icc filename.cpp -openmp -Wall -pedantic
(icc version 14.0.1 (compatible with gcc version 4.7.0))
or
g++ filename.cpp -fopenmp -Wall -pedantic
(gcc version 4.7.2 20130108 [gcc-4_7-branch version 195012] (SUSE Linux))
but after compiling with icc I get runtime errors such as:
*** Error in `./a.out': munmap_chunk(): invalid pointer: 0x00007fff31bcc980 ***
when calling the second function (pass_vector_by_value_and_use_firstprivate)
Thus, an error occurs only when using the firstprivate clause (which should call the copy constructor), and the vector is passed by the value of the function (which should also refer to the copy constructor). If you donβt either skip the vector, but create it locally in a function or not use firstprivate, no error! On gcc, I get no errors.
I am wondering how the code creates undefined behavior or if it is an error in icc?
c ++ gcc vector openmp icc
user1304680 May 21 '14 at 7:26 2014-05-21 07:26
source share