Equation Solution  
    High Performance by Design
Navigation Tree  

 
neuLoop  
'- - Basic Concept
'- - Limitations & Status
'- - Do Subroutine
'- - Functions
|     '- - nlp$use
|     '- - nlp$done
|     '- - nlp$staysoftcore
|     '- - nlp$loop
|     '- - nlp$syncloop
|     '- - nlp$barrier
|     '- - Parallel Locks
|     '- - nlp$getce
|     '- - User Times
'- - Where To Download
'- - Manual Tool!
 



Requirements for Do-Subroutine


        In neuLoop, do-statements must be written in a subroutine. The do-subroutine has three requirements that a program should meet.

FIRST REQUIREMENT: RECURSIVE ATTRIBUTE

        In Fortran, variables are allocated as static by default. However, do-subroutine is for soft cores to access, and all local variables should be allocated as "automatic". To allocate local variables as automatic, a simple way is to declare the subroutine with "recursive" attribute. For example, we have the following typical do-loop:

      do var = start, stop, step
            !! statement 1
            !! statement 2
         ...............
      end do

When writing the do-statements in a subroutine, we declare the subroutine with "recursive" attribute, for example,

       recursive subroutine sub(var,a,b,c,,,,,)
       !! declaration of dummy arguments
       !! statement 1
       !! statement 2
       ...............
       return
       end recursive subroutine

The first requirement is to declare do-subroutine with recursive attribute.

SECOND REQUIREMENT: THE FIRST DUMMY ARGUMENT

        The second requirement is that the first dummy argument must be the loop variable and must be 4-byte integer. Other common variables can be passed by dummy arguments, or can be passed by common statement or module, but the first dummy argument must be loop variable. For example, we have the following loop:

      do i = 1, 10000
            a(i) = b(i)+c(i)
            d(i) = i
       end do

The do-variable is i. When we rewrite those two statements into a subroutine, the first dummy argument must be the loop variable. For example,

       recursive subroutine sub(i,a,b,c,d)
       integer :: i,a(1),b(1),c(1),d(1)
       a(i) = b(i)+c(i)
       d(i) = i
       return
       end subroutine sub

The first dummy argument must be the loop variable. Other common variables can be passed by common statement or module. For example, we can pass common variables by module, and the subroutine is rewritten as:

       recursive subroutine sub(i)
       use common_data
       integer :: i
       a(i) = b(i)+c(i)
       d(i) = i
       return
       end subroutine sub

How to pass common variables is under programmer decision, but the first dummy argument must be loop variable and must be 4-byte integer.

THIRD REQUIREMENT: External Statement

        The third requirement is the dispatcher must declare every do-subroutine by external statement. For example, the caller must declare the do-subroutine as:

 :  external sub

Conversion of do-statement into a subroutine must meet the above three requirements.

A FORTRAN EXAMPLE

    Program example
!
! A program has the three requirements
! for do-subroutine
!
! Set a(i) = i for illustration.
! It is not worth setting a(i) = i in parallel.
!
 
!
! default attribute
!
    implicit none
 
!
! variables and parameters
!
    integer (kind = 4), parameter :: n = 1000
    integer (kind = 4), parameter :: chunk = 3
    integer (kind = 4) :: a(n)
    integer (kind = 4) :: i
    integer (kind = 4) :: j
 
!
! declaration of do-subroutine
!
    external sub
 
!
! call neuLoop to demand four soft cores
!
    call nlp$use(4)
 
!
! call neuLoop to set a(i) = i in parallel
!
    call nlp$syncloop_7(sub,1,n,chunk,a,n,chunk)
 
!
! call neuLoop to deallocate soft cores
!
    call nlp$done
 
!
! end of example
!
    end program example
 
 
!
! do-subroutine: sub
!
    recursive subroutine sub(i,a,n,chunk)
    implicit none
    integer (kind = 4) :: i,a(1),n,chunk,j
    do j = i, min0(n,i+chunk-1)
       a(j) = j
    end do
    return
    end subroutine sub