其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
简单的mpi发送和接收的程序

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

简单的mpi发送和接收的程序

随手写了个简单的mpi发送和接收的程序。
这个和都志辉老师的那本<mpi并行程序设计> p.30 是差不多的。

有一点,要想看到效果,要保证 MpiRun.exe  -np x $(TargetPath)
的这个 x 大于 1。呵呵。



#include <mpi.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>

int _tmain(int argc, _TCHAR* argv[])
{
int myid,numprocs;
int namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
    char buff[100];

MPI_Init(&argc,&argv);

MPI_Comm_rank(MPI_COMM_WORLD,&myid);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Get_processor_name(processor_name,&namelen);

fprintf(stderr,
"\nHello World!Process %d of %d on %s\n",
myid,numprocs,processor_name);

    memset(buff,0,100);
    if (myid == 0)
    {
        strcpy(buff,"0 to 1");
        MPI_Send(buff,strlen(buff),MPI_CHAR,1,99,MPI_COMM_WORLD);
        fprintf(stderr,"\nsend:%s",buff);
    }
    else
    {
        MPI_Status sta;
        if (myid == 1)
        {
            MPI_Recv(buff,20,MPI_CHAR,0,99,MPI_COMM_WORLD,&sta);
            fprintf(stderr,"\nrecv:%s",buff);
        }
    }

MPI_Finalize();
    
    if (myid == 0)
    {
        printf("\nPress a key and exit.\n");

        getch();
    }
return 0;
}




相关文章

相关软件