Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
documentation:examples:sommevecvecpar.f90 [2013/02/06 15:47] – créée ltaulell | documentation:examples:sommevecvecpar.f90 [2023/01/13 09:37] (Version actuelle) – supprimée ccalugar | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | <code fortran SommeVecVecPAR.f90> | ||
- | program Somme | ||
- | implicit none | ||
- | include ' | ||
- | integer, dimension( MPI_STATUS_SIZE ) :: statut | ||
- | integer, parameter :: etiquette=100 | ||
- | |||
- | integer :: A(10), | ||
- | integer :: i | ||
- | integer :: nb_procs, | ||
- | |||
- | call MPI_INIT(code) | ||
- | |||
- | call MPI_COMM_SIZE(MPI_COMM_WORLD, | ||
- | call MPI_COMM_RANK(MPI_COMM_WORLD, | ||
- | |||
- | if (rang .eq. 0) then | ||
- | do i=1,10 | ||
- | A(i) = i | ||
- | B(i) = 10 - i | ||
- | enddo | ||
- | |||
- | write ( *, * ) 'LES DEUX VECTEURS :' | ||
- | |||
- | write (*,*) 'A = ', | ||
- | write (*,*) 'B = ', | ||
- | endif | ||
- | |||
- | call MPI_BARRIER ( MPI_COMM_WORLD ,code) | ||
- | |||
- | if (rang .eq. 0) then | ||
- | call MPI_SEND (A(1:5),5, MPI_INTEGER , | ||
- | call MPI_SEND (A(6:10),5, MPI_INTEGER , | ||
- | call MPI_SEND (B(1:5),5, MPI_INTEGER , | ||
- | call MPI_SEND (B(6:10),5, MPI_INTEGER , | ||
- | endif | ||
- | |||
- | call MPI_RECV (Aloc,5, MPI_INTEGER , | ||
- | call MPI_RECV (Bloc,5, MPI_INTEGER , | ||
- | |||
- | call MPI_BARRIER ( MPI_COMM_WORLD ,code) | ||
- | if (rang .eq. 0) then | ||
- | write ( *, * ) 'LES DEUX VECTEURS LOCAUX :' | ||
- | endif | ||
- | |||
- | |||
- | print *,'Je suis le proc ', | ||
- | write (*,*) 'A local ( proc ', | ||
- | write (*,*) 'B local ( proc ', | ||
- | |||
- | call MPI_BARRIER ( MPI_COMM_WORLD ,code) | ||
- | do i=1,5 | ||
- | Cloc(i) = Aloc(i) + Bloc(i) | ||
- | enddo | ||
- | |||
- | if (rang .eq. 0) then | ||
- | write ( *, * ) 'LE VECTEUR SOMME LOCAL : ' | ||
- | endif | ||
- | |||
- | call MPI_BARRIER ( MPI_COMM_WORLD ,code) | ||
- | |||
- | write (*,*) 'C local ( proc ', | ||
- | |||
- | call MPI_BARRIER ( MPI_COMM_WORLD ,code) | ||
- | |||
- | call MPI_SEND (Cloc(1: | ||
- | |||
- | if (rang .eq. 0) then | ||
- | call MPI_RECV (C(1:5),5, MPI_INTEGER , | ||
- | call MPI_RECV (C(6:10),5, MPI_INTEGER , | ||
- | endif | ||
- | |||
- | if (rang .eq. 0) then | ||
- | write ( *, * ) 'LE VECTEUR SOMME :' | ||
- | write (*,*) 'C = ', | ||
- | endif | ||
- | |||
- | |||
- | call MPI_FINALIZE(code) | ||
- | |||
- | end program | ||
- | </ |