Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
documentation:examples:sommevecvecpar.c [2020/08/25 15:58] – modification externe 127.0.0.1documentation:examples:sommevecvecpar.c [2023/01/13 09:37] (Version actuelle) – supprimée ccalugar
Ligne 1: Ligne 1:
-<code c SommeVecVecPAR.c> 
-#include <stdio.h> 
-#include <mpi.h> 
-void main (int argc, char *argv[])  
-{ 
-    MPI_Status statut; 
-    int etiquette=100; 
  
-    int A[10],B[10],C[10],Aloc[5],Bloc[5],Cloc[5]; 
-    int i; 
-    int nb_procs,rang; 
- 
-    MPI_Init(&argc, &argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nb_procs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rang); 
- 
-    if (rang == 0)  
-    { 
-       for(i=1;i<=10;i++) 
-             
-           A[i-1] = i; 
-           B[i-1] = 10 - i; 
-       } 
- 
-       printf ("LES DEUX VECTEURS :\n"); 
- 
-       printf ("A = "); 
-       for(i=1;i<=10;i++) 
-       { 
-           printf (" %d ", A[i-1]); 
-       } 
- 
-       printf ("\nB = "); 
-       for(i=1;i<=10;i++) 
-       { 
-           printf (" %d ",B[i-1]); 
-       } 
-    } 
- 
-    MPI_Barrier (MPI_COMM_WORLD); 
- 
-    if (rang == 0)  
-    { 
-        MPI_Send (&A[0],5, MPI_INT ,0,etiquette, MPI_COMM_WORLD); 
-        MPI_Send (&A[5],5, MPI_INT ,1,etiquette, MPI_COMM_WORLD); 
-        MPI_Send (&B[0],5, MPI_INT ,0,etiquette+1, MPI_COMM_WORLD); 
-        MPI_Send (&B[5],5, MPI_INT ,1,etiquette+1, MPI_COMM_WORLD); 
-    } 
- 
-    MPI_Recv (&Aloc[0],5, MPI_INT ,0,etiquette, MPI_COMM_WORLD,&statut); 
-    MPI_Recv (&Bloc[0],5, MPI_INT ,0,etiquette+1, MPI_COMM_WORLD,&statut); 
- 
-    MPI_Barrier ( MPI_COMM_WORLD); 
-    if (rang == 0)  
-    { 
-       printf ("\nLES DEUX VECTEURS LOCAUX :\n"); 
-    } 
- 
-    MPI_Barrier ( MPI_COMM_WORLD); 
- 
-    printf ("Je suis le proc %d parmi %d processus", rang,nb_procs); 
- 
-    printf (" \n A local ( proc %d ) = ",rang); 
-    for(i=1;i<=5;i++) 
-    { 
-        printf (" %d ",Aloc[i-1]); 
-    } 
- 
-    MPI_Barrier ( MPI_COMM_WORLD); 
- 
-    printf (" \n B local ( proc %d ) = ",rang); 
-    for(i=1;i<=5;i++) 
-    { 
-        printf (" %d ",Bloc[i-1]); 
-    } 
- 
-    MPI_Barrier ( MPI_COMM_WORLD); 
- 
-    for(i=1;i<=5;i++) 
-    { 
-      Cloc[i-1] = Aloc[i-1] + Bloc[i-1]; 
-    } 
- 
-    MPI_Barrier ( MPI_COMM_WORLD); 
- 
-    if (rang == 0) 
-    { 
-       printf (" \n LE VECTEUR SOMME LOCAL : "); 
-    } 
- 
-    MPI_Barrier ( MPI_COMM_WORLD); 
- 
-    printf (" \n C local ( proc %d ) = ",rang); 
-    for(i=1;i<=5;i++) 
-    { 
-        printf (" %d ",Cloc[i-1]); 
-    } 
- 
-    MPI_Barrier ( MPI_COMM_WORLD); 
- 
-    MPI_Send (&Cloc[0],5, MPI_INT, 0, etiquette, MPI_COMM_WORLD); 
- 
-    if (rang == 0)  
-    { 
-        MPI_Recv (&C[0],5, MPI_INT, 0, etiquette, MPI_COMM_WORLD,&statut); 
-        MPI_Recv (&C[5],5, MPI_INT, 1, etiquette, MPI_COMM_WORLD,&statut); 
-    } 
- 
-    if (rang == 0)  
-    { 
-        printf (" \n LE VECTEUR SOMME : "); 
-        for(i=1;i<=10;i++) 
-        { 
-           printf (" %d ",C[i-1]); 
-        } 
-        printf (" \n "); 
-    } 
- 
-    MPI_Finalize(); 
-} 
-</code> 
documentation/examples/sommevecvecpar.c.1598371112.txt.gz · Dernière modification : 2020/08/25 15:58 de 127.0.0.1