用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

芙蓉妹妹    -  云代码空间

——

MPI_Reduce

2019-04-21|353阅||

摘要:MPI_Reduce(sbuf,rbuf,3,MPI_INT,MPI_SUM,0,comm);

#include <stdio.h>
#include "mpi.h"
#include <malloc.h>

int main(int argc, char ** argv){
    int rank,size,rbuf[3],sbuf[3],i;
    MPI_Comm comm = MPI_COMM_WORLD;
    MPI_Status status;
    MPI_Init(&argc,&argv);
    MPI_Comm_size(comm, &size);
    MPI_Comm_rank(comm, &rank);
    printf("Process %d :",rank);
    for(i = 0;i< 3;i++){
        sbuf[i] = rank*10 + i;
        printf(" %d",sbuf[i]);
    }
    putchar('\n');
    MPI_Reduce(sbuf,rbuf,3,MPI_INT,MPI_SUM,0,comm);
    if(rank == 0){
        printf("Total sum = :");
        for(i = 0;i< 3;i++)
            printf(" %d",rbuf[i]);
        putchar('\n');
    }
    MPI_Barrier(comm);
    MPI_Finalize();
    return 0;
}
MPI_Reduce(
sbuf,            //address of send bufer
rbuf,            //address of recvive buffer
3,                //number of elements in send buffer
MPI_INT,      //data type of elements of send buffer
MPI_SUM,     //reduce of operation
0,                //rank of root process
comm
);

顶 0踩 0收藏
分享到:
更多
文章评论
    发表评论