I have difficulty trying to correct a simple OpenMP loop to avoid having a "definitely lost" memory leak from valgrind. Without OpenMP, Valgrind doesn't return problematic memory leaks while it is when OpenMP pragmas are activated. Here is an example of a simple matrix assignment that leaks:
void assign(const Matrix& src, Matrix& dest) {
int nr = src.rows();
int nc = src.cols();
#pragma omp parallel for num_threads(NUM_THREADS) firstprivate(nr, nc) schedule(dynamic, 1)
for (int32 c = 0 ; c < nc ; ++c) {
for (int32 r = 0 ; r < nr ; ++r)
mat(r,c) = src(r,c);
}
Here are the leak details:
==19732== 304 bytes in 1 blocks are definitely lost in loss record 8 of 11
==19732== at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==19732== by 0x40136D4: allocate_dtv (dl-tls.c:322)
==19732== by 0x40136D4: _dl_allocate_tls (dl-tls.c:539)
==19732== by 0x68A926E: allocate_stack (allocatestack.c:588)
==19732== by 0x68A926E: pthread_create@@GLIBC_2.2.5 (pthread_create.c:539)
==19732== by 0x647899F: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==19732== by 0x6474CB9: GOMP_parallel (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==19732== by 0x43BF6D: void assign(Matrix const&, Matrix&) (assign.h:267)
==19732== by 0x43BB30: Matrix::Matrix(Matrix const&) (matrix.h:1351)
==19732== by 0x43A451: DistanceTest::read_matrix(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (test_distance.cpp:85)
==19732== by 0x43A702: DistanceTest::read_data() (test_distance.cpp:106)
==19732== by 0x43DE10: test::ABTest::Run(int) (ab_test.cpp:44)
Is it a huge deal having a "definitely lost" because of OpenMP ? Is it resulting from a bad habit in my pragma writing or because of the difficulties Valgrind has studying the OpenMP framework ?