并行化Fortran 90

时间:2016-04-25 01:33:27

标签: matrix parallel-processing fortran fortran90

我最近开始学习如何在Fortran中并行化程序,现在我试图在程序中包含它。

问题在于我使用Lapack(计算特征值和特征向量),显然这与并行化例程产生冲突,因为根据矩阵大小,它会计算一些特征值(小尺寸的错误值,并且它没有& #39; t根据等于或大于10x10的矩阵计算它们。

当我只使用一个线程运行程序时,它可以正常工作。

program nuevo

use omp_lib  

  implicit none
  integer ::i,j,k,l,kk,jj,red,ok,info,LWORK,stat1 
  integer :: m,n,q,rea,i0,j0,CHUNK,CHUNKSIZE   !!!! rea= number of realizations >1
  PARAMETER(m=10,n=10,rea=12,LWORK=2*m*n,ok=m*n,CHUNKSIZE=rea/2)  
  complex*8 t,aa,tt,ww !! Caution with the dimension of the variables
  INTEGER, DIMENSION(1)::  SEED, OLD
  integer, parameter ::  ikind=selected_real_kind(p=15)
  real (kind=ikind) ::  pi
  real ( kind = 8 ) wtime
  real*8 D, DD(m,n),zz, X(2*m*n*rea), XX(m*n,2*rea), ss, hh, HARVEST(2*n*m*rea), w
  complex*16 A(m*n,m*n), WORK(3*n-2,3*n-2)
  real*8 RWORK(2*m*n), b(m*n), f


!!!!!!!!!!!!RANDOM NUMBERS!!!!!!!!!!!!!!!!!!!


   SEED(1) = 67937
    CALL RANDOM_SEED
    CALL RANDOM_SEED(SIZE=k)
    CALL RANDOM_SEED(GET=OLD(1:k))
    CALL RANDOM_NUMBER(HARVEST)
        X=HARVEST


!!!!!!!!!!!RANDOM MATRIX!!!!!!!!!!!!!!!!!!!!!!  

    XX=RESHAPE( X, (/ m*n, 2*rea /) )
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
wtime = omp_get_wtime ( )
!call omp_set_num_threads(1)  

t=1.0d0                  !!  hoppings  

CHUNK=CHUNKSIZE

!$OMP PARALLEL
!$OMP DO SCHEDULE(STATIC,CHUNK) ORDERED


 do  jj=0,2*(rea-1),2  !!for the realizations
  w=0.1d0              !! desorder ratio
  ww=n
  q=m*n
  aa=(0.0d0,1.0d0) !! Complex number
   A=0d0
   b=0d0
   f=2/ww

   do j=1,(m*n)
    if (XX(j,jj+1)<0.5) then
       ss=1.0d0
     else
       ss=-1.0d0
     end if
    A(j,j)=ss*0.5d0*w*XX(j,jj+2)        !!  Diagonal terms with slighty random modifications 
    end do

    !!!!!!!!!!!!!!!!!!!!!!!!!!!
    !!!!!!  MATRIX    !!!!!!!!!
    !!!!!!!!!!!!!!!!!!!!!!!!!!!


 !! In the x direction  (i odd)
         do i=1,m,2
            do j=1,n-2,2
               A((j*m)+i,((j+1)*m)+i)=t
            end do
         end do  
!!  In the x direction  (i even)
         do i=2,m,2
            do j=1,n-1,2
               A(((j-1)*m)+i,(j*m)+i)=t
            end do
         end do  

!!  In the y direction  

         do j=1,n
            do i=1,m-1
            A(((j-1)*m)+i,((j-1)*m)+i+1)=t*exp(pi*j*f*aa) !!  phase factor due to the magnetic field 
            end do
         end do
!! Periodic boundaries in x direction


         do i=1,m,2
           A(i,(i+m*n-m))=t
         end do

!!    Periodic boundaries in y direction

            do j=1,n
               A(((j-1)*m)+1,j*m)=t*(exp(-pi*j*f*aa)) 
            end do

!!=========Conjugate===============

         do i0=1,m*n
            do j0=1,m*n
               A(j0,i0)=dconjg(A(i0,j0))
            end do
         end do

call ZHEEV('V', 'U', ok, A, ok, b, WORK, LWORK, RWORK, info) !!Lapack routine
    do i=1,m*n
        write(*,*) b(i)
        write(*,*) ' '
    end do

end do     !! for the realizations


!$OMP END DO
!$OMP END PARALLEL

end program nuevo

0 个答案:

没有答案