用户注册



邮箱:

密码:

用户登录


邮箱:

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

发表随想


还能输入:200字

芙蓉妹妹    -  云代码空间

——

Design a program to implement ping-ping.

2019-04-19|567阅||

摘要:communication between at two process. In this program, process0 send a data to process1. And process1 increases this data and reply it to pr

#include<stdio.h>
#include"mpi.h"
int main(int argc, char **argv)
{
    MPI_Comm comm = MPI_COMM_WORLD;
    int size, rank, num = 0;
    MPI_Status status;
    MPI_Init(&argc,&argv);
    MPI_Comm_size(comm,&size);
    MPI_Comm_rank(comm,&rank);
    while(num < 9)
    {
        if(rank == 0)
        {
            if(num == 0)
            {
                MPI_Send(&num,1,MPI_INT,1,99,comm);
                printf("Process 0 send %d to process 1.\n",num);
            }
            MPI_Recv(&num,1,MPI_INT,1,99,comm,&status);
            num += 1;
            MPI_Send(&num,1,MPI_INT,1,99,comm);
            printf("Process 0 send %d to process 1.\n",num);
        }
        else if (rank == 1)
        {
            MPI_Recv(&num,1,MPI_INT,0,99,comm,&status);
            num += 1;
            MPI_Send(&num,1,MPI_INT,0,99,comm);
            printf("Process 1 send %d to process 0.\n",num);
        }
    }
    MPI_Finalize();
    return 0;
}

注意send和recv函数第一个参数都是地址!!!

顶 2踩 2收藏
文章评论
    发表评论

    个人资料

    • 昵称: 芙蓉妹妹
    • 等级: 资深程序员
    • 积分: 1710
    • 代码: 104 个
    • 文章: 25 篇
    • 随想: 0 条
    • 访问: 32 次
    • 关注

    标签

    最新提问

      站长推荐