This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Question on OpenMP and Fortran memory allocation
- From: "Wirawan Purwanto" <wirawan0 at gmail dot com>
- To: fortran at gcc dot gnu dot org
- Date: Mon, 7 Jul 2008 10:48:01 -0400
- Subject: Question on OpenMP and Fortran memory allocation
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=nbcp2uUvgL739YvOJJLeXabyZyJbVOU1pl5WB/atvBk=; b=FQmzgmhK8TWL5y15Xjt9A2p07tBsewANJXEjunXQ2PxMG5cRaqFXJaA3s7T24gD6qu GinlhmAhbRFy9utMBfu8RM7JzPy5SkJHjHLKsgAeQpnH896hf6Upf6m6GsUKYfSkIp9Y PKR0uWq8taDY1rKEKlCVeHi22KaOJufXoXolA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=sMYzSK5o9YkRcskX2feRfW1ZkTBaXQroYW2DY1IrHp1R1KT1oV9X5NJauR11KQx0vO A0E0LvGtXRCg5JPySw2vWNWuY+T2w87KXO62qjOo2nHmffPXexD0+Wcrl+zcwAMphpWq EvsYRgKd6WgJLTYxvFt4Zo2cvgj89PzZLvzxk=
This must be a silly question, but I have been fighting over an issue
through the weekend, and could not find a definitive answer on the
matter of GNU Fortran memory allocation thread safety. The question is
very simple: is GNU Fortran's memory allocation routines (ALLOCATE and
DEALLOCATE) guaranteed to be thread-safe with OpenMP? OpenMP 2.5 specs
indicates that these routines must be thread-safe to be compliant with
OpenMP standard.
I have GNU Fortran 4.3.1 compiled on my machine, which has an Intel
Pentium M processor (x86-32 system). I tested a simple code (shown at
the end of this email) and assembled it using command line:
$ gfortran -fopenmp -S alloc.F90 -O2
(The -O2 is not necessary, but it cleans the code.)
It reveals that GNU Fortran uses a simple C malloc() and free()
routines. For example:
.globl __alloc_mod_MOD_alloc_mem
.type __alloc_mod_MOD_alloc_mem, @function
__alloc_mod_MOD_alloc_mem:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $4, %esp
movl 8(%ebp), %ebx
movl (%ebx), %eax
movl $537, 8(%ebx)
movl $1, 16(%ebx)
movl $50, 20(%ebx)
testl %eax, %eax
movl $1, 12(%ebx)
jne .L2
movl $400, (%esp)
call malloc
testl %eax, %eax
je .L6
movl %eax, (%ebx)
movl $-1, 4(%ebx)
addl $4, %esp
popl %ebx
popl %ebp
ret
...
The C library in my machine is GNU libc version 2.5 . Is glibc's
free() and malloc() thread-safe? I tried to find this information on
the web but could not find it. The only link that seems to indicate
this is:
http://www.linux-kongress.org/1997/gloger.html
Thanks,
Wirawan
------------
module alloc_mod
implicit none
contains
subroutine alloc_mem(arr)
real*8, allocatable :: arr(:)
allocate(arr(50))
end subroutine
subroutine dealloc_mem(arr)
real*8, allocatable :: arr(:)
deallocate(arr)
end subroutine
subroutine print1(v)
real*8 :: v
write(*,*) v
end subroutine
end module
program alloc_test
use alloc_mod
implicit none
real*8, allocatable :: arr1(:)
integer :: i
!$omp parallel default(none) &
!$omp & private(arr1, i)
call alloc_mem(arr1)
!$omp do
do i = 1, 50
arr1(i) = i * 251
call print1(arr1(i))
enddo
!$omp end do
call dealloc_mem(arr1)
!$omp end parallel
end program
--
Wirawan Purwanto
College of William and Mary
Physics Department
Williamsburg, VA 23187