473,326 Members | 2,126 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,326 software developers and data experts.

(OpenMP, C++ME, System.Threading.Thread) -> Resource Leak.

Here is the source code of my C++/ME app. When I run it I can use "Windows Task Manager" to see that thread HANDLEs are leaking.

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include <omp.h>
  3.  
  4. public __gc class TestClass
  5. {
  6. public:
  7.     void ThreadProc()
  8.     {
  9.         int sum = 0;
  10.  
  11. #pragma omp parallel for reduction(+:sum)
  12.         for ( int i = 0; i < 10000; i++ )
  13.         {
  14.             sum += i;
  15.         }
  16.  
  17.         System::Console::WriteLine( sum.ToString() );
  18.     }
  19. };
  20.  
  21. int main()
  22. {
  23.     for (;;)
  24.     {
  25.         TestClass __gc * o = __gc new TestClass();
  26.         System::Threading::Thread __gc * t = __gc new System::Threading::Thread( 
  27.                     __gc new System::Threading::ThreadStart( o, &TestClass::ThreadProc ) );
  28.  
  29.         t->Start();
  30.  
  31.         System::Threading::Thread::get_CurrentThread()->Sleep( 100 );
  32.     }
  33. }
  34.  
If I put something that is not using Open MP into the ThreadProc no HANDLEs will be leaked.
I realize that what happens is: Omp creates unmanaged threads inside a managed thread (i.e. System::Threading::Thread). I just have very little idea about what could be wrong with it. If somebody will try to reproduce this, I am currently using VS2005.
Thanks for all your comments and suggestions.
Oct 1 '07 #1
2 2508
I think i have got ur problem. there are unmanaged threads when using openmp.is it so?

openmp architecture is like when u specify the openmp pragma, it creates a new thread for ur loop and once finished joins the main thread.this might be ur problem. I am not versatile in openmp. But this is a new concept only less ppl use it.so keep in touch to discuss about openmp
Oct 5 '07 #2
We recently discovered that the thread leak has nothing to do with .NET. The same leak occurs even if we run OpenMP code inside a Win32 thread. So, here is the new example. Suggestions\ideas, please?

Expand|Select|Wrap|Line Numbers
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <omp.h>
  4.  
  5. int calculateArithmeticalProgressionSumOMP( int a1, int d, int n )
  6. {
  7.     int sum = 0;
  8.     omp_set_num_threads(3);
  9. #pragma omp parallel 
  10.     {
  11. #pragma omp for reduction (+: sum)
  12.         for( int i = 0; i < n; i++)
  13.         {
  14.             int a = a1 + i * d;
  15.             sum += a;                                                                                                                                                                                      
  16.         }
  17.     }
  18.     return sum;
  19. }
  20.  
  21. DWORD threadFunc(LPVOID pParams)
  22. {
  23.     int sum = calculateArithmeticalProgressionSumOMP(0, 1, 10000);
  24.     printf("%d\n", sum);
  25.     return 0;
  26. }
  27.  
  28. int main()
  29. {
  30.     //create some threads
  31.     for(int i = 0; i < 100; i++)
  32.     {
  33.         HANDLE handle;
  34.         handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE )threadFunc, NULL, 0, NULL);
  35.         WaitForSingleObject(handle, INFINITE);
  36.         Sleep(100); //imitating some other work
  37.     }
  38.  
  39.     return 0;
  40. }
  41.  
  42.  
Nov 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: David | last post by:
I've written a small windows service, and I'm having a problem that I'm spending a lot more time on than I'd like. If anyone has experienced this problem and has any hints or solutions; they would...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
1
by: Brian C. Barnes | last post by:
Will OpenMP (or some other parallelizing technology) be considered for C#, like C++ already has? Brian C. Barnes
5
by: Vladimir_petter | last post by:
Hello guys, Looks like this technology is comming along with VS2005. Anybody has an expirience of using it along with C++? What are the patterns? Thanks, Vladimir.
1
by: Carl J. Van Arsdall | last post by:
Hey everyone, I know I've posted several questions regarding python and python's parallel capabilities so bear with me as I've never attempted to incite discussion. However, today I'm...
2
by: san | last post by:
Hi, I am not sure whether this is the right group to post this. Still here I go: I am new to OpenMP. I wrote a very simple code in C++. The code is as below #include <iostream.h> #include...
0
by: BallCOMET | last post by:
I have an application that I built with Visual Studio 2005 and for which I enabled OpenMP. If I open the compiled binary in Visual Studio, this is the manifest that is embedded in the executable...
2
by: clevrmnkey | last post by:
I've had nothing but trouble from the System.Net.Mail objects, but I finally need to make them work, and I can't for the life of me see what I'm doing wrong. I pared back my mail transaction to...
16
by: Paul Schwann | last post by:
Hi group, I am relatively new to C# (although I have a lot of programming excperience in other languages like Java and C). Currently I am searching for a solution to this problem: Suppose you...
6
by: Renato Perini | last post by:
Hi all!!! I'm trying to find a *good* book about OpenMP and C, but I can't find anything specific. Can you advice me some good (and updated) books about OpenMP using the C interface? I'd like a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.