找回密码
 注册
查看: 2306|回复: 1

问大家一下关于mpi一个输出次序的问题

[复制链接]
发表于 2009-2-19 22:01:29 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
问大家一下关于mpi一个输出次序的问题

对于一下代码:

#include"mpi.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#pragma comment (lib, "mpi.lib")

#define SIZE 10
/* Amount of time in seconds to wait for the receipt of the second Ssend message */
static int src = 0;
static int dest = 1;

int main(int argc,char *argv[])
{
        printf("fin start!\n");
        int rank; /* My Rank (0 or 1) */
        int act_size = 0;
        int flag, np, rval, i;
        int buffer[SIZE];
        MPI_Status status, status1, status2;
        int count1, count2;
        MPI_Init(&argc, &argv);
        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
        MPI_Comm_size( MPI_COMM_WORLD, &np );
        if (np != 2)
        {
                fprintf(stderr, "*** This program uses exactly 2 processes! ***\n");
                MPI_Abort( MPI_COMM_WORLD, 1 );
        }
        act_size = 5;/*最大消息长度*/
        if (rank == src)
        {
                printf("ok\n");

                /*当前进程为发送进程*/
                act_size = 1;
                MPI_Ssend( buffer, act_size, MPI_INT, dest, 1, MPI_COMM_WORLD );
                /*同步消息发送发送一个整型数tag标识为1*/
                fprintf(stderr,"MPI_Ssend %d data,tag=1\n", act_size);
                act_size = 4;
                MPI_Ssend( buffer, act_size, MPI_INT, dest, 2, MPI_COMM_WORLD );
                /*同步发送4个整型数tag标识为2*/
                fprintf(stderr,"MPI_Ssend %d data,tag=2\n", act_size);
        }else if (rank == dest)
        {
                /*当前进程为接收进程*/
                MPI_Recv( buffer, act_size, MPI_INT, src, 1, MPI_COMM_WORLD,&status1 );
                /*标准消息接收这里指定的消息长度act_size是最大消息长度tag为1*/
                MPI_Recv( buffer, act_size, MPI_INT, src, 2, MPI_COMM_WORLD,&status2 );
                /*标准消息接收这里指定的消息长度act_size是最大消息长度tag为2*/
                MPI_Get_count( &status1, MPI_INT, &count1 );/*消息1包含的数据的个数*/
                fprintf(stderr,"receive %d data,tag=%d\n",count1,status1.MPI_TAG);
                MPI_Get_count( &status2, MPI_INT, &count2 );/*消息2包含的数据的个数*/
                fprintf(stderr,"receive %d data,tag=%d\n",count2,status2.MPI_TAG);
        }
        MPI_Finalize();


        printf("fin end!\n");


        return 0;

}




Vc 2005 环境可以编译通过

我的问题是:为什么会有这种输出次序呢?

MPI_Ssend 1 data,tag=1
MPI_Ssend 4 data,tag=2
fin start!
ok
fin end!
fin start!
fin end!
receive 1 data,tag=1
receive 4 data,tag=2
Press any key to continue . . .



我的理解中  fin start!  一定是要首先被打印出来的呀!
大家帮忙分析分析好么?
运行环境winxp
编译:VC++ 2005

[ 本帖最后由 art_codes 于 2009-2-20 10:14 编辑 ]
 楼主| 发表于 2009-2-20 10:14:15 | 显示全部楼层
大家看看呀 ^_^
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表