473,385 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2410
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: J. Campbell | last post by:
what happens to allocated memory when a program terminates before the memory is released. For example: int main(){ int* array; int a_size = 1000; array = new int; for(int i = 0; i < a_size;...
6
by: Mike | last post by:
..NET 1.1 Hi. My C# .NET application has a memory leak - if I leave it running for hours then the system ends up using 500MB+ of virtual memory, which is released immediately when I close the...
25
by: Zeng | last post by:
I finally narrowed down my code to this situation, quite a few (not all) of my CMyClass objects got hold up after each run of this function via the simple webpage that shows NumberEd editbox. My...
9
by: Anton | last post by:
{Willy Skjveland} Hi, how can I trace a Memory leak in aspnet_wp.exe? {Rheena} One moment please while I search it for you. It may take me a few moments {Willy Skjveland} I need to find out...
1
by: bw | last post by:
I have a basic custom collection that throws a new exception if the item(key) is not found in the collection. This is used as part of a calling function. It all works correctly, the problem...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
8
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of...
17
by: Mike | last post by:
Hello, I have following existing code. And there is memory leak. Anyone know how to get ride of it? function foo has been used in thousands places, the signature is not allowed to change. ...
22
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.