469,903 Members | 1,542 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Memory leak using omp parallel for within a thread

Hello,

I'm trying to use the command "#pragma omp parallel for" within a thread but
each thread that is created (and stopped again) produces a memory leak of
about 44kB.

If the entry for "Stack Reserver Size" in
Properties->ConfigurationsProperties->Linker->System is increased, the memory
leak grows up to 10MB and more dependent on the stack reserve size.

Below is a code sample where 100 threads are iteratively created and
stopped, each time leading to the described memory leak.

I've tested the code on Intel dual and quad core processors.

Any help is highly appreciated
#include <Windows.h>
#include <process.h>
#include <cstdio>

#include <omp.h>

unsigned int __stdcall cThreadProc(void* param)
{
Sleep(3000);
#pragma omp parallel for
for (int y=0; y<3000; y++){}
return 0;
}

int main(int argc, char* argv[])
{

for (int k = 0; k < 100; k++)
{
unsigned attr = 0;
HANDLE handle = (HANDLE)_beginthreadex(NULL, 0, cThreadProc, 0,
CREATE_SUSPENDED, &attr);
int prio = GetThreadPriority(GetCurrentThread());
SetThreadPriority(handle, prio);
fprintf(stdout, "begin thread\n");
ResumeThread(handle);

WaitForSingleObject(handle, INFINITE);
CloseHandle(handle);
}

return 0;
}

Oct 29 '07 #1
2 2166
Hannes Steinke wrote:
Hello,

I'm trying to use the command "#pragma omp parallel for" within a
thread but each thread that is created (and stopped again) produces a
memory leak of about 44kB.
A leak based on what measurement? How do you know that it's not simply
memory that was allocated for worker thread use that will be reused by later
workers?

-cd
Oct 29 '07 #2
Hi,

I've analyzed the memory consumption of the application using the process
explorer software for Windows which shows a gradual increase of the used
memory each time a new thread is created. This memory is allocated when the
thread starts but the memory is not released at the end of each loop when the
thread is stopped.

When the line "#pragma omp parallel for" is omitted, then the memory is
released at the end of each thread as expected. It seems that each time when
omp commands are used within a thread, stack memory is allocated that is only
released at the end of the whole application and not at the end of the thread.

"Carl Daniel [VC++ MVP]" wrote:
Hannes Steinke wrote:
Hello,

I'm trying to use the command "#pragma omp parallel for" within a
thread but each thread that is created (and stopped again) produces a
memory leak of about 44kB.

A leak based on what measurement? How do you know that it's not simply
memory that was allocated for worker thread use that will be reused by later
workers?

-cd
Oct 30 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by J. Campbell | last post: by
6 posts views Thread by Mike | last post: by
9 posts views Thread by Anton | last post: by
23 posts views Thread by James | last post: by
8 posts views Thread by Adrian | last post: by
22 posts views Thread by Peter | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.