[comp.lang.fortran] Parallel Fortran question

john%ghostwheel.unm.edu@ariel.unm.edu (John Prentice) (12/11/90)

I want to code the following for a shared memory parallel system:

      program yuppie
c
c        loop over subroutine
c
      integer n,nmax
      parameter (nmax=10)
      real hippie(nmax)
      do 10 n=1,nmax
          call yippie (hippie(n))
                  .
                  .
                  .
          call yippie (hippie(n))
                  .
                  .
                  .
   10 continue
      end
      subroutine yippie (hippie)
      real hippie
      logical first
      save first
      data first /.true./
c
      if (first) then
          .
        [initializations]
          .
          first=.false.
      endif
        .
        .
        .
      end

When yippie gets called the first time, it does some initializations.
Subsequent calls for the same loop iteration should not repeat the
initialization however (assume I am parallelizing the loop in the main
routine).  The way I wrote yippie works fine on a non-shared memory
machine, but not on a shared memory system.  This is because the save
statement causes yippie to always save first to the same memory location,
no matter which processor is being used.  On the Cray, you could use task
common to save the value of first, but there is no way to initialize task
common (that I know of).  Any suggestions?  Thanks.

John Prentice
john@unmfys.unm.edu

john@ghostwheel.unm.edu (John Prentice) (12/11/90)

I posted this earlier today, but it doesn't seem to have showed up.  If
you get two copies, my apologies.  John


I want to code the following for a shared memory parallel system:

      program yuppie
c
c        loop over subroutine
c
      integer n,nmax
      parameter (nmax=10)
      real hippie(nmax)
      do 10 n=1,nmax
          call yippie (hippie(n))
                  .
                  .
                  .
          call yippie (hippie(n))
                  .
                  .
                  .
   10 continue
      end
      subroutine yippie (hippie)
      real hippie
      logical first
      save first
      data first /.true./
c
      if (first) then
          .
        [initializations]
          .
          first=.false.
      endif
        .
        .
        .
      end

When yippie gets called the first time, it does some initializations.
Subsequent calls for the same loop iteration should not repeat the
initialization however (assume I am parallelizing the loop in the main
routine).  The way I wrote yippie works fine on a non-shared memory
machine, but not on a shared memory system.  This is because the save
statement causes yippie to always save first to the same memory location,
no matter which processor is being used.  On the Cray, you could use task
common to save the value of first, but there is no way to initialize task
common (that I know of).  Any suggestions?  Thanks.

John Prentice
john@unmfys.unm.edu

booker%network@ucsd.edu (Booker bense) (12/14/90)

In article <12191@hubcap.clemson.edu> john%ghostwheel.unm.edu@ariel.unm.edu (John Prentice) writes:
>I want to code the following for a shared memory parallel system:
>
>      program yuppie
>c
>c        loop over subroutine
>c
>      integer n,nmax
>      parameter (nmax=10)
>      real hippie(nmax)
>      do 10 n=1,nmax
>          call yippie (hippie(n))
>                  .
>          call yippie (hippie(n))
>                  .
>   10 continue
>      end
>      subroutine yippie (hippie)
>      real hippie
>      logical first
>      save first
>      data first /.true./
>c
>      if (first) then
>          .
>        [initializations]
>          .
>          first=.false.
>      endif
>        .
>      end
>
>When yippie gets called the first time, it does some initializations.
>Subsequent calls for the same loop iteration should not repeat the
>initialization however (assume I am parallelizing the loop in the main
>routine).  The way I wrote yippie works fine on a non-shared memory
>machine, but not on a shared memory system.  This is because the save
>statement causes yippie to always save first to the same memory location,
>no matter which processor is being used.  On the Cray, you could use task
>common to save the value of first, but there is no way to initialize task
>common (that I know of).  Any suggestions?  Thanks.
>


- 
A better way to do this for a shared memory machine is to put first
into the arguements for the subroutine. i.e. 
 
	
     do 10 n=1,nmax
	  first = .true. 
          call yippie (hippie(n),first)
          first = .false.
                  .
                  .
                  .
          call yippie (hippie(n),first)
                  .
                  .
                  .
	  
    10 continue
  
And make first a local ( or non-shared or private ) variable. If you
are using the CRI autotasking directives, something like

CMIC$ DO ALL SHARED( hippie ) PRIVATE(first,n)

 I'm assuming that you need first = true for each n ,i.e.  first means
first call in the do loop. I quess you said this didn't you. 




-Booker C. Bense
/* benseb@grumpy.sdsc.edu */