Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

Max number of openmp locks?

James_Benze
Beginner
528 Views
Is it possible that there are a maximum number of openmp locks one can allocate? I'm using ifort 11.1, and after a large amount of lock allocations, omp_init_lock() starts returning 0s.

So does this mean that I'm some how "out of locks"?
EDIT: Also, I can't seem to replicate this on trivial test case. Any other reason omp_init_lock() would return 0?
0 Kudos
3 Replies
SergeyKostrov
Valued Contributor II
528 Views
Hi James,

Quoting James Benze
Is it possible that there are a maximum number of openmp locks one can allocate?

[SergeyK] I just checked an OpenMP v3.1 Specifications and I haven't found any referencesrelated to a
maximum number of locks.

Please take a look at a chapter 3.3 Lock Routings andexample A.43 on a page 292.
In the example an array of locks (1000 in total) is initialized.

I'm using ifort 11.1, and after a large amount of lock allocations, omp_init_lock() starts returning 0s.

So does this mean that I'm some how "out of locks"?

[SergeyK] I'm not sure. Would you be able to provide more technical details?

EDIT: Also, I can't seem to replicate this on trivial test case.Any other reason omp_init_lock() would return 0?

[SergeyK] It cannot return 0 because 'omp_init_lock' functiondoesn't return anything. It is declared as follows:

void omp_init_lock( omp_lock_t *lock );

Best regards,
Sergey
0 Kudos
pbkenned1
Employee
528 Views

Are you using ALLOCATE() to obtain your OpenMP locks? The underlying lock representation is based on the INTEGER KIND that will hold an address, ie, the return value of intrinsic function INT_PTR_KIND(). The result is 4 bytes on IA-32 architecture, or8 bytes on Intel 64 architecture.

So if you're using ALLOCATE(), the maximum number of OpenMP locks you can obtain is limited by the largest chuck of heap you can successfully allocate. We've tested up to 5 million locks in a single program!

You could declare your array of OpenMP locks:
integer (kind=omp_lock_kind), allocatable :: omp_locks(:)

Then check the status return value for any error:
allocate (omp_locks(num_in_block), stat=alloc_err)

Completeexample:

program omp_lock_alloc

use omp_lib_kinds

integer (kind=omp_lock_kind), allocatable :: omp_locks(:)

integer alloc_err

integer, parameter :: num_in_block =256

allocate (omp_locks(num_in_block), stat=alloc_err)

if(alloc_err .EQ. 0) then

print *,'allocated ',num_in_block,' omp locks'

else

print *,' failed to allocate omp locks'

endif

end program omp_lock_alloc



>ifort -Qopenmp omp_lock_alloc.f90

Intel Visual Fortran Intel 64 Compiler XE for applications running on Intel 64, Version 12.1.4.325 Build 20120410

Copyright (C) 1985-2012 Intel Corporation. All rights reserved.

Microsoft Incremental Linker Version 10.00.30319.01

Copyright (C) Microsoft Corporation. All rights reserved.

-out:omp_lock_alloc.exe

>omp_lock_alloc.exe

allocated 256 omp locks



Patrick Kennedy
Intel Developer Support
0 Kudos
Vladimir_P_1234567890
528 Views
Hello James,
Did you check a memory consumption? The one of the reason to 'out-of-locks' might be out of memory for your app.
--Vladimir
0 Kudos
Reply