Allocatable private array in openmp parallel do directive

Allocatable private array in openmp parallel do directive

Hi,  I have a problem and I did not find a solution : I want to use parallelism in the free code  , but a problem occurred in the allocation of arrays: 

PROGRAM LMTART

USE PARA_CONTROL
    use omp_lib
    INTEGER I,J
    real, allocatable, dimension(:) :: a
    PARA_FIRST=.True.
    !$OMP PARALLEL  DEFAULT(firstprivate) 
    !$OMP DO
    DO I = 1, 10
    if(PARA_FIRST) then
    allocate(a(100))
    DO J = 1, 10
    a(j)=j    
    ENDDO
    endif
    write(*,*) (a(J),J=1,10)
    PARA_FIRST=.False.
    ENDDO
    !$OMP END DO
    !$OMP END PARALLEL

   END

It should be noted that : do not  reserved  the table "a" before entering in the  DO  directive

9 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Please provide more description than 'a problem occurred'.  Compilation problem? Runtime problem?  Probably the code compiles (but I can't be sure since it depends on module PARA_CONTROL), so I suppose this is a runtime problem.  Please provide details.  I don't see suspicious, other than a race condition on the write() statement.

Patrick

..this code fails with a message error saying "allocatable array is already allocated",  code not works!

Please Help me !!!!!!!!!!!!!!

We have to be able to reproduce (or at least understand) your issue before we can help you.

What version of the compiler are you using? 

Is logical variable PARA_FIRST modified outside of the code you showed us?  If so, you may need to provide the source for module PARA_CONTROL, along with the code that is modifying PARA_FIRST.

 

If I define PARA_FIRST as a local variable, all is well with ifort-14.0.3:

 

$ cat U520439.f90
PROGRAM LMTART

!!!USE PARA_CONTROL

     use omp_lib
     implicit none
     INTEGER I,J
     logical PARA_FIRST
     real, allocatable, dimension(:) :: a

     PARA_FIRST=.True.
     !$OMP PARALLEL  DEFAULT(firstprivate)
     !$OMP DO
     DO I = 1, 10
     if(PARA_FIRST) then
     allocate(a(100))
     DO J = 1, 10
     a(j)=j
     ENDDO
     endif
     write(*,*) (a(J),J=1,10)
     PARA_FIRST=.False.
     ENDDO
     !$OMP END DO
     !$OMP END PARALLEL
   END

 

$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.3.174 Build 20140422
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

$ ifort -openmp U520439.f90 && ./a.out
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
   1.000000       2.000000       3.000000       4.000000       5.000000
   6.000000       7.000000       8.000000       9.000000       10.00000
$

 

Patrick

Patrick Kennedy , work ,goooooooooooooood hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh!!!!!

Where is the problem????

Note :Where is deallocate procedure !!!! deallocate procedure is the problem ?

If you allocate something in a PARALLEL region, it is automatically deallocated at the end of the parallel region, so deallocation is not the problem in the code you have shown us. 

Patrick

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui