?? kkk.c
字號:
#include <stdio.h>
#include <mpi.h>
/*An example using MPI_Bcast*/
int main (int argc, char *argv[])
{
int myrank, size, i;
double pi;
double area = 0;
double total, *back_ray;
pi=0.0;
MPI_Init(&argc, &argv); /* Initialize MPI */
MPI_Comm_rank(MPI_COMM_WORLD, &myrank); /* Get my rank */
MPI_Comm_size(MPI_COMM_WORLD, &size); /* Get the total number of processes */
//printf("Iam process %d of %d: My value of Pi=%f!\n", myrank, size,pi);
if(myrank==0)/*This initializes the value of pi on the root process*/
{
pi=3.14;
printf("I am broadcasting the value of Pi\n");
back_ray=(double*)malloc(size*sizeof(double));
}
MPI_Bcast(&pi,1,MPI_DOUBLE,0,MPI_COMM_WORLD);/*Note that every process calls MPI_Bcast!*/
area=pi*myrank*myrank;
MPI_Gather(&area,1,MPI_DOUBLE, back_ray,1,MPI_DOUBLE, 0,MPI_COMM_WORLD);
if(myrank == 0){
total=0;
for(i=0;i<size;i++){
total=total+back_ray[i];
}
printf("total= %f \n ",total);
}
MPI_Finalize(); /* Terminate MPI */
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -