Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Time splitting issue

charlotte_M_
Beginner
2,731 Views

 Hello Everyone,

I'm trying to solve a problem use time splitting method.  For this i have to solve linear systems  of equation using tridag (fortran ) routine.

I have two problems

The first one is that the coefficients  use in tridag are 2 D array while this routine use 1 D array.

What i did to overcome this is the following (just a example):

  do  k=1,NT         ! Main loop over the time step

!Compute  the solution of the first equation 

do i=1, N1

do j= 1, N2

   A(j) = x(i)*y(j)

  B(j)= x(i)*y(j)

  C(j)=x(i)*y(j)

 End do 

 Call tridag( A,B,C,F0, F1, N)     !F0  is a two dimensional function , F1, a one dimensional function

 End do 

!Once done i will use F1 as the initial condition for the second equation

 Do j =1, N2

 Do i=1,N1

  E(i)= xx(i)*y(jj)

 F(i) =xx(i)*yy(j)

 G(i)= xx(i)*yy(i)

End do 

  Call tridag(E,F,G,F1,F2,n1)

end do 

!Next step Write result in the file, for different time

!Finally   i update my initial condition

   DO i=1,N1

 DO j=1,N2

   F0(i,j) =F2(i,j)

  end do

end do

END DO         !ENd of the time loop

 

****** The second  problem is that , i have the same result for different  time that i print the solution.

 I am doing something wrong?

 sorry for the long text

 

  Thank you

0 Kudos
1 Solution
jimdempseyatthecove
Honored Contributor III
2,715 Views

Pass F0(i,:) and F0(:,j).

Note, in the case of F0(i,:), the compiler will generate a temporary (because the slice has a stride of N1, size of N2).
For the F0(:,J), the compiler should use the data in place (because the slice has a stride of 1, size of N1).

Jim Dempsey

View solution in original post

0 Kudos
22 Replies
jimdempseyatthecove
Honored Contributor III
273 Views

For parallelization, consider the following untested code:

!$omp parallel
!$omp master
do  k=1,NT         ! Main loop over the time step
  !Compute  the solution of the first equation
  do i=1, N1
    !$omp task firstprivate(i) private(j)
    do j= 1, N2
      A(j) = x(i)*y(j)
      B(j)= x(i)*y(j)
      C(j)=x(i)*y(j)
    End do 

    Call tridag( A,B,C,F0(i,:), F1(i,:), N)     !F0  is a two dimensional function , F1, a one dimensional function
    !$omp end task
  End do
  !$omp taskwait
  ! *** Note, on prior iteration (after first iteration)
  ! *** a task was enqueued (and may have been pending) to write the results
  ! *** of the prior iteration's F2. The above taskwait will also wait for
  ! *** that task to complet, thus freeing up the use of F2 for this iteration.

  !Once done i will use F1 as the initial condition for the second equation
  Do j =1, N2
    !$omp task firstprivate(j) private(i)
    Do i=1,N1
      E(i)= xx(i)*y(jj)
      F(i) =xx(i)*yy(j)
      G(i)= xx(i)*yy(i)
    End do 
    Call tridag(E,F,G,F1(:,j),F2(:,j),n1)
    !$omp end task
  end do 
  !$omp taskwait

  !$omp task private(i,j) ! and any other conflicting variables
  !Next step Write result to the file, for different time
  ...
  !$omp end task
  ! *** Note, the write task will be in progress during the next iteration of k's computation
  ! *** of the first tridag

  ! Now update F0 for initial condition for next time step
  F0 = F2
END DO         !ENd of the time loop
! *** now wait for the last write of F2
!$omp taskwait
!$omp end master
!$omp end parallel

Jim Dempsey

0 Kudos
jimdempseyatthecove
Honored Contributor III
273 Views

Also, if the timestep (k) is to be written to the output file, then make it firstprivate(k) on the task that performs the write.

Jim Dempsey

0 Kudos
Reply