472,796 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,796 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 2369
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...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.