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

王朝other·作者佚名  2006-01-09
宽屏版  字体: |||超大  

简单的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;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有