FW: Is GMP safe for using on multi core processors with openmp or pthreads?

David Carver dcarver at tacc.utexas.edu
Thu Jul 30 18:40:20 CEST 2009


Torbjörn,

The program's function was to provide a very simple example of the memory leakage problem with using the default malloc/free with GMP and compiled with OpenMP.  When reporting a problem I try to provide a very simple test case. 

 

#include <stdlib.h>

#include <gmp.h>

 

#define CORES 4

#define AMAX 64

 

int main(int argc, char *argv[])

{

   int i;

   mpz_t array[AMAX];

 

#ifdef _OPENMP

#pragma omp parallel for default(shared) private(i) num_threads(CORES)

#endif

   for (i = 0 ; i < AMAX ; i++) 

      mpz_init(array[i]);

 

#ifdef _OPENMP

#pragma omp parallel for default(shared) private(i) num_threads(CORES)

#endif

   for (i = 0 ; i < AMAX ; i++) 

      mpz_clear(array[i]);   

 

   exit(0);

}

 

When the example program is compiled without the OpenMP flag it does not exhibit the memory leak problem.

I have reproduced the memory leak using this example program on both Linux and Windows operating system and with GCC, the Intel, and Microsoft Visual Studio compilers. 

 

I did read the section in the GMP manual sections http://www.gmplib.org/manual/Reentrancy.html#Reentrancy <http://www.gmplib.org/manual/Reentrancy.html%23Reentrancy>  and http://gmplib.org/manual/Custom-Allocation.html#Custom-Allocation and while the information was good for a simple threaded recursive program it does not address issues with multi threaded and openmp applications.

 

In addition, the memory leaks were reported with the multi threads GMP example program using the following debugging tools: Valgrind, DDT, and Intel's Thread Checker.  Because DDT and Intel's Thread Checker are commercial productions and are not generally available I only included the output from Valgrind runs for the example program build with and without OpenMP.

 

Since multi core processors have become main stream and GNU, Intel, MicroSoft are actively supporting openmp and threads, researchers and developers are starting to report memory leaks in application libraries using malloc/free.  See ftp://ftp.cs.utexas.edu/pub/emery/papers/asplos2000.pdf

 

Also, some vendors like Sun are providing alternate malloc/free libraries for Solaris for multi threaded application.

See http://developers.sun.com/solaris/articles/multiproc/multiproc.html

 

Finally, using the information from the previous two articles I was able to link the example program with the Hoards malloc library and have Valgrind not report any memory leaks.

 

I suggest maybe adding another section in the GMP documentation to address multi threaded issues with GMP.

 

Thank you,

David Carver

 

 

------------------------------

Date: Tue, 28 Jul 2009 18:48:02 +0200

From: Torbjorn Granlund <tg at gmplib.org>

Subject: Re: FW: Is GMP safe for using on multi core processors with

        openmp or       pthreads?

To: David Carver <dcarver at tacc.utexas.edu>

Cc: "gmp-discuss at gmplib.org" <gmp-discuss at gmplib.org>

Message-ID: <86fxcgsqil.fsf at shell.gmplib.org>

Content-Type: text/plain; charset=iso-8859-1

 

David Carver <dcarver at tacc.utexas.edu> writes:

 

  Is the GMP mpz routine safe for using on multi core processors with

  openmp or pthreads with the Linux malloc in glibc?

 

That's a very general question.

 

There is a section in the GMP manual about reentrany.  Have you read it?

If I understand your question, it should provide a reasonable answer.

 

  Valgrind is reporting a memory leak in a simple GMP program when

  compiled with GCC 4.4 and -fopenmp

 

I am sorry, but I am not able to make much sense of the program or the

output.

 

--

Torbj?rn

 

 

------------------------------

___________________________________________

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 474 bytes
Desc: not available
URL: <http://gmplib.org/list-archives/gmp-discuss/attachments/20090730/1b7db105/attachment.bin>


More information about the gmp-discuss mailing list