LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Srinivasa Prade Patri (Srinivasa.Patri_at_[hidden])
Date: 2005-02-22 17:35:45


Hi!
    Thanks for your reply. In my code node 0 is reading the input matrix from file and is distributing the columns to the corresponding nodes. The code is for LU decomposition and am not using the algorithm from any of the Linear alegbra libraries. I have written the code my self and i know it is not efficient .
                   My code is running fine for matrix sizes below 15000*15000. Iam not using dynamic memory allocation techniques in my code. Does this help me in running for higher matrix problem sizes.
                 To be honest i dont know what exactly a swap space mean.

Regards
Srinivasa Patri
Here is the code for your reference....
PROGRAM main
      INCLUDE "mpif.h"
      PARAMETER (N=16400)
      COMPLEX*8 a(N,N)
      INTEGER col(N)
      INTEGER size,myrank
      INTEGER i,j,k
      INTEGER endcnt
      INTEGER status(MPI_STATUS_SIZE),status1(MPI_STATUS_SIZE),ierr
      DOUBLE PRECISION starttime,endtime

      CALL MPI_INIT(ierr)
* Determining the size of the communication
      CALL MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)

* Determining the rank of each processor
      CALL MPI_COMM_RANK(MPI_COMM_WORLD, myrank, ierr)
      
      starttime = MPI_WTIME()
* Assigning columns to different processors
      DO i = 1, N
      col(i) = MOD(i-1, size)
      ENDDO
      
* Open the matrix input file to read
      OPEN (UNIT=1,FILE="matrix16834.data",STATUS='OLD')
    
* Reading the matrix data from input file
      IF (myrank.EQ.0) THEN
          DO j=1,N
             DO i=1,N
                READ (UNIT=1,FMT=*) a(i,j)
             END DO
          END DO
      END IF
    
      IF (myrank.EQ.0) THEN
         DO i=1,N
            IF (col(i).NE.0) THEN
                CALL MPI_SEND(a(1,i),N,MPI_COMPLEX,col(i),50,
     & MPI_COMM_WORLD,ierr)
            END IF
         END DO
      ELSE
         DO j=1,n
            IF (col(j).EQ.myrank) THEN
               CALL MPI_RECV(a(1,j),N,MPI_COMPLEX,0,50,
     & MPI_COMM_WORLD,status,ierr)
            END IF
         END DO
      END IF

      DO k = 1,N-1
         IF (col(k).EQ. myrank) THEN
            DO i = k+1, N
               a(i,k) = a(i,k) / a(k,k)
            ENDDO
         ENDIF
      CALL MPI_BCAST(a(k,k), N-k+1, MPI_COMPLEX, col(k),
     & MPI_COMM_WORLD, ierr)
      
      DO j = k+1, N
      IF (col(j).EQ. myrank) THEN
      DO i = k+1, N
      a(i,j) = a(i,j) - a(i,k) * a(k,j)
      ENDDO
      END IF
      ENDDO
      ENDDO
c------------------------------------------------------------------------------
    DO i=1,N
         IF (myrank.NE.0) THEN
            IF (col(i).EQ.myrank) THEN
c WRITE (*,*) "PROCESSOR=",myrank,"COLUMN=",i
               CALL MPI_SEND(a(1,i),N,MPI_COMPLEX,0,60,
     & MPI_COMM_WORLD,ierr)
            END IF
         ELSE
           IF (col(i).NE.0) THEN
            CALL MPI_RECV(a(1,i),N,MPI_COMPLEX,col(i),
     & 60,MPI_COMM_WORLD,status1,ierr)
c WRITE (*,*) "RECIEVING COLUMN=",i
           END IF
         END IF
       END DO
C-------------------------------------------------------------------------------
      IF (myrank.NE.0) THEN
         CALL MPI_SEND(a(1,1),1,MPI_COMPLEX,0,52,
     & MPI_COMM_WORLD,ierr)
     
      ELSE
         endcnt=1
         DO WHILE(endcnt.LT.size)
            CALL MPI_RECV(a(1,1),1,MPI_COMPLEX,
     & MPI_ANY_SOURCE,MPI_ANY_TAG,MPI_COMM_WORLD,status,ierr)
   
            IF (status(MPI_TAG).EQ.52) THEN
               endcnt=endcnt+1
* WRITE(*,*)endcnt
            END IF
         END DO
       OPEN(UNIT=11,FILE="lu_16834.data")
       DO j=1,N
             DO i=1,N
                WRITE (UNIT=11,FMT=*) a(i,j)
             END DO
       END DO
       END IF
       endtime=MPI_WTIME();
       WRITE (*,*) "Processor ",myrank," Time ",(endtime-starttime)/60,
     & "minutes"
       CALL MPI_FINALIZE(ierr)
       END