
Untitled
By: a guest on
Jun 21st, 2012 | syntax:
C++ | size: 2.06 KB | hits: 17 | expires: Never
// mpi_5_1.cpp: определяет точку входа для консольного приложения.
//
#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <mpi.h>
#include <malloc.h>
int main(int argc, char *argv[])
{
int rank, size, i;
int buffer[10];
int proc,headproc, msglen=64;
MPI_Status status;
MPI_Status *Statuses;
char *sendbuf;
char *recvbuf;
int TIMES=5;
int TAG1=1;
MPI_Request *Requests;
double R,s,Duration,Finish,Start;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (size < 2)
{
printf("Please run with two processes.\n");
fflush(stdout);
MPI_Finalize();
return 0;
}
sendbuf =(char *) malloc(sizeof(char)*8388608);
recvbuf =(char *) malloc(sizeof(char)*8388608);
if (rank == 0)
{
for(int j = 1; j <= 18; j++)
{
Start = MPI_Wtime();
for(int i = 0; i < TIMES; i ++)
{
MPI_Isend(sendbuf,msglen,MPI_CHAR,proc,TAG1, MPI_COMM_WORLD,&Requests[0]);
MPI_Irecv(recvbuf,msglen,MPI_CHAR,proc,TAG1, MPI_COMM_WORLD,&Requests[1]);
MPI_Waitall(2,Requests,Statuses);
}
Finish = MPI_Wtime();
Duration = Finish-Start;
R=2*TIMES*msglen/Duration;
s=msglen/R-Duration;
printf("Num=%d, Time is %f, R=%f, lat=%f \r\n",j,Duration,R,s);
msglen+=msglen;
}
}
if (rank == 1)
{
for(int j = 1; j <= 18; j++)
{
for(int i = 0; i < TIMES; i ++)
{
MPI_Irecv(sendbuf,msglen,MPI_CHAR,proc,TAG1, MPI_COMM_WORLD,&Requests[1]);
MPI_Isend(recvbuf,msglen,MPI_CHAR,proc,TAG1, MPI_COMM_WORLD,&Requests[0]);
MPI_Waitall(2,Requests,Statuses);
}
msglen+=msglen;
}
fflush(stdout);
}
MPI_Finalize();
free(sendbuf);
free(recvbuf);
return 0;
}