!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -*- Mode: F90 -*- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! transpose.f90  --- Utilisation d'un type derive (type_transpose)
!!                    pour transposer une matrice.
!!
!!
!! Auteur          : Isabelle DUPAYS (CNRS/IDRIS - France)
!!                   <Isabelle.Dupays@idris.fr>
!! 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


PROGRAM transpose
  USE MPI
  IMPLICIT NONE
  INTEGER, PARAMETER                     :: nb_lignes=5,nb_colonnes=4,&
                                            etiquette=1000
  INTEGER                                :: code,rang,type_ligne,&
                                            type_transpose,taille_reel,i,j
  REAL, DIMENSION(nb_lignes,nb_colonnes) :: A
  REAL, DIMENSION(nb_colonnes,nb_lignes) :: AT
  INTEGER(kind=MPI_ADDRESS_KIND)         :: pas
  INTEGER, DIMENSION(MPI_STATUS_SIZE)    :: statut


  !Initialisation de MPI
  CALL MPI_INIT(code)

  !-- Savoir qui je suis
  CALL MPI_COMM_RANK(MPI_COMM_WORLD,rang,code)

  !-- Initialisation de la matrice AT
  AT(:,:) = 0.

  !Connaitre la taille du type de base MPI_REAL

  !Construction du type derive type_transpose pour transposer la
  !matrice A composee de nb_lignes et de nb_colonnes

  !Validation du type cree type_transpose


  IF (rang == 0) THEN
     !Initialisation de la matrice A sur le processus 0
     A(:,:) = RESHAPE( (/ (i,i=1,nb_lignes*nb_colonnes) /), &
                       (/ nb_lignes,nb_colonnes /) )

     PRINT *,'Matrice A'
     DO i=1,nb_lignes
        PRINT *,A(i,:)
     END DO

     !Envoi de la matrice A au processus 1 avec le type type_transpose


  ELSE
     !Reception pour le processus 1 dans la matrice AT


     PRINT *,'Matrice transposee AT'
     DO i=1,nb_colonnes
        PRINT *,AT(i,:)
     END DO

  END IF

  !Sortie de MPI
  CALL MPI_FINALIZE(code)

END PROGRAM transpose
