[Myricom help #24562] [Fwd: thread safe malloc?]

Loic Prylli <[email protected]> Tue, 13 Apr 2004 01:16:10 -0400
Newsgroups gmane.network.myrinet.general
Message-ID <[email protected]>
Zaheerul Arefeen wrote:

>Hi
>I'm using mpich-1.2.5..12 on top of gm 1.6.5 on a
>linux cluster.
>Please see my attached code, where i created multiple
>pthreads from each mpi processes and used malloc and
>free iteratively in the thread body. at the end,
>  
>

Thanks for creating a small example for your problem.

>[...]
>1. sometimes the main exit without completing the
>thread body or main body (possibly some processes
>crush!!)
>
>2. sometimes some of the processes complete execution
>and other waits for thread join (i guess).
>
>But the very same code runs successfully on Sun mpi in
>a shared memory machine. 
>  
>

What configuration are you running on, ia64? ia32?

I have tried your code with a couple of different configurations, I was 
unable to get any problems on ia32 with a  few runs.

On 64bit machines I needed the following patch to your program to avoid 
corrupting the stack (after that, on a few runs I wasn't able to get any 
problems):
--- afs/mpit3.c 2004-04-12 21:48:57.000000000 -0700
+++ afs/mpit4.c 2004-04-12 21:48:26.000000000 -0700
@@ -53,7 +53,8 @@
    int total_process, process_id;
    pthread_t thread[NUM_THREADS];
    pthread_attr_t attr;
-   int rc, t, status,prov;
+   int rc, t, prov;
+   void *status;
    MPI_Status stat;


>I wonder the new mpich-gm 1.2.5..12 does provide
>thread safe malloc!! or i'm not getting this because
>its on top of gm-1 rather than gm-2.
>
If your problem is not just related to the 64bit issue above, please 
send the details of your configuration: architecture, compiler, OS 
version(particularly libc), dynamic/static linking, so that we can speed 
the resolution of your problem. mpich-gm comes with the thread-safe 
ptmalloc2 implementation for malloc. So malloc() is supposed to be 
thread-safe. More technical details on this: since 1.2.5..11, to  avoid 
to have to link -lpthread for mono-threaded programs, mpich-gm/ptmalloc2 
relies on the weak definitions of libc for pthread_mutex, and an 
internal weak definition for pthread_mytex_trylock(). For real 
multi-threaded programs (linked with -lpthread), the real pthread 
definitions for these symbols should override the weak ones. While the 
proper working of this dynamic (or static) linking has been tested on 
several configurations (various mix of ia32/ia64/x86_64 icc/gcc/pgi) it 
was not tested exhaustively on every possible compiler/arch/OS. If 
malloc appears non-thread-safe on your configuration we definitely want 
to know and identify the problem.

>mpich-gm log files where i can find where my code is
>actually executed(may be not on all machines of my
>machine file) and whether or not my processes are
>being crused at some nodes.
>

Unfortunately, there is no mpich-gm log file. The machines used for 
execution might depend on your local configuration, wether you have a 
batch system and local mpirun scripts. If you use the standard supplied 
mpirun scripts (without a specific machine file), 
<mpi-inst-dir>/share/machines.ch_gm.LINUX might give a clue.


Regards,

Loic