Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory leak when using OpenMP
    primarykey
    data
    text
    <p>The below test case runs out of memory on 32 bit machines (throwing std::bad_alloc) in the loop following the "post MT section" message when OpenMP is used, however, if the #pragmas for OpenMP are commented out, the code runs through to completion fine, so it appears that when the memory is allocated in parallel threads, it does not free correctly and thus we run out of memory.</p> <p>Question is whether there is something wrong with the memory allocation and deletion code below or is this a bug in gcc v4.2.2 or OpenMP? I also tried gcc v4.3 and got same failure.</p> <pre><code>int main(int argc, char** argv) { std::cout &lt;&lt; "start " &lt;&lt; std::endl; { std::vector&lt;std::vector&lt;int*&gt; &gt; nts(100); #pragma omp parallel { #pragma omp for for(int begin = 0; begin &lt; int(nts.size()); ++begin) { for(int i = 0; i &lt; 1000000; ++i) { nts[begin].push_back(new int(5)); } } } std::cout &lt;&lt; " pre delete " &lt;&lt; std::endl; for(int begin = 0; begin &lt; int(nts.size()); ++begin) { for(int j = 0; j &lt; nts[begin].size(); ++j) { delete nts[begin][j]; } } } std::cout &lt;&lt; "post MT section" &lt;&lt; std::endl; { std::vector&lt;std::vector&lt;int*&gt; &gt; nts(100); int begin, i; try { for(begin = 0; begin &lt; int(nts.size()); ++begin) { for(i = 0; i &lt; 2000000; ++i) { nts[begin].push_back(new int(5)); } } } catch (std::bad_alloc &amp;e) { std::cout &lt;&lt; e.what() &lt;&lt; std::endl; std::cout &lt;&lt; "begin: " &lt;&lt; begin &lt;&lt; " i: " &lt;&lt; i &lt;&lt; std::endl; throw; } std::cout &lt;&lt; "pre delete 1" &lt;&lt; std::endl; for(int begin = 0; begin &lt; int(nts.size()); ++begin) { for(int j = 0; j &lt; nts[begin].size(); ++j) { delete nts[begin][j]; } } } std::cout &lt;&lt; "end of prog" &lt;&lt; std::endl; char c; std::cin &gt;&gt; c; return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload