Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2007

Tip: Looking for answers? Try searching our database.

Memory leak using omp parallel for within a thread

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hannes Steinke - 29 Oct 2007 13:43 GMT
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;
}
Carl Daniel [VC++ MVP] - 29 Oct 2007 16:10 GMT
> 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
Hannes Steinke - 30 Oct 2007 07:59 GMT
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.

> > Hello,
> >
[quoted text clipped - 7 lines]
>
> -cd

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.