Memory leak using omp parallel for within a thread

G

Guest

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;
}
 
C

Carl Daniel [VC++ MVP]

Hannes said:
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
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top