Introduction MPI - Chap2 - Slide 3
Introduction MPI - Chap2 - Slide 3
Introduction MPI - Chap2 - Slide 3
#include <stdio.h>
#include <stdlib.h>
//#include "memory.h" //include file with function prototypes for memory management
#include "mpi.h"
int main(int argc, char **argv){
int Tag1=1; int Tag2=2;
int num_procs;
int ID;
int buffer_count=10;
long *buffer;
int i;
MPI_Status stat;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD, &ID);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
if(num_procs !=2) MPI_Abort(MPI_COMM_WORLD, 1);
buffer=(long *)malloc(buffer_count* sizeof(long));
for(i=0; i<buffer_count; i++)
buffer[i]=(long) i;
MPI_Finalize();
}
#include "mpi.h"
#include<stdio.h>
#include<string.h>
main(int argc, char *argv[])
{
int id, nb, len;
char mesage[10];
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &nb);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
strcpy(mesage, "Hello");
len = strlen(mesage)+1;
MPI_Bcast(mesage, len, MPI_CHAR, 0, MPI_COMM_WORLD);
printf("I am the process: %d and say: %s\n", id, mesage);
MPI_Finalize();
}
Execution:
mpiexec –np 4 test1 (to execute the program on 4 processors)
Exercice:
Trapezoidal Integration (serial implementation and the corresponding MPI implementation)
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: