File: MPI.c

package info (click to toggle)
netpipe 2.3-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 160 kB
  • ctags: 109
  • sloc: ansic: 979; makefile: 113
file content (157 lines) | stat: -rw-r--r-- 3,675 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*****************************************************************************/
/* "NetPIPE" -- Network Protocol Independent Performance Evaluator.          */
/* Copyright 1997, 1998 Iowa State University Research Foundation, Inc.      */
/*                                                                           */
/* This program is free software; you can redistribute it and/or modify      */
/* it under the terms of the GNU General Public License as published by      */
/* the Free Software Foundation.  You should have received a copy of the     */
/* GNU General Public License along with this program; if not, write to the  */
/* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   */
/*                                                                           */
/*     * MPI.c              ---- MPI calls source                            */
/*****************************************************************************/
#include    "netpipe.h"
#include    <mpi.h>

#ifndef lint
static const char rcsid[] =
	"$Id: MPI.c,v 1.4 1998/09/24 13:50:33 ghelmer Exp $";
#endif

#ifdef BSEND
char *messbuff;
#define MAXBUFSIZE (10*1024*1024)
#endif


int Setup(ArgStruct *p)
{
    int nproc;

    MPI_Comm_rank(MPI_COMM_WORLD, &p->prot.iproc);
    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
    {
        char s[255];
        gethostname(s,253);
        printf("%d: %s\n",p->prot.iproc,s);
        fflush(stdout);
    }
    p->prot.nbor = !p->prot.iproc;
	
    if (nproc != 2)
    {
	printf("Need two processes\n");
	exit(-2);
    }

    if (p->prot.iproc == 0)
	p->tr = 1;
    else
	p->tr = 0;
	
#ifdef BSEND
    messbuff = (char *)malloc(MAXBUFSIZE * sizeof(char));
    if (messbuff == NULL)
    {
        printf("Can't allocate for message buffer\n");
        exit(-1);
    }
    MPI_Buffer_attach(messbuff, MAXBUFSIZE);
#endif

}   

void Sync(ArgStruct *p)
{
	MPI_Barrier(MPI_COMM_WORLD);
}

static int recvPosted = 0;
static MPI_Request recvRequest;

void PrepareToReceive(ArgStruct *p)
{
	/*
	  Providing a buffer for reception of data in advance of
	  the sender sending the data provides a major performance
	  boost on some implementations of MPI, particularly shared
	  memory implementations on the Cray T3E and Intel Paragon.
	*/
	if (recvPosted)
	{
	    printf("Can't prepare to receive: outstanding receive!\n");
	    exit(-1);
	}
	MPI_Irecv(p->buff, p->bufflen, MPI_BYTE,
		  p->prot.nbor, 1, MPI_COMM_WORLD, &recvRequest);
	recvPosted = -1;
}

void SendData(ArgStruct *p)
{
#ifdef BSEND
	MPI_Bsend(p->buff, p->bufflen, MPI_BYTE, p->prot.nbor, 1, MPI_COMM_WORLD);
#else
	MPI_Send(p->buff, p->bufflen, MPI_BYTE, p->prot.nbor, 1, MPI_COMM_WORLD);
#endif
}

void RecvData(ArgStruct *p)
{
	MPI_Status status;
	if (recvPosted)
	{
		MPI_Wait(&recvRequest, &status);
		recvPosted = 0;
	}
	else
	{
		MPI_Recv(p->buff, p->bufflen, MPI_BYTE, 
				p->prot.nbor, 1, MPI_COMM_WORLD, &status);
	}
}


void SendTime(ArgStruct *p, double *t)
{
#ifdef BSEND
	MPI_Bsend(t, 1, MPI_DOUBLE, p->prot.nbor, 2, MPI_COMM_WORLD);
#else
	MPI_Send(t, 1, MPI_DOUBLE, p->prot.nbor, 2, MPI_COMM_WORLD);
#endif
}

void RecvTime(ArgStruct *p, double *t)
{
	MPI_Status status;

	MPI_Recv(t, 1, MPI_DOUBLE, p->prot.nbor, 2, MPI_COMM_WORLD, &status);
}


void SendRepeat(ArgStruct *p, int rpt)
{
#ifdef BSEND
	MPI_Bsend(&rpt, 1, MPI_INT, p->prot.nbor, 2, MPI_COMM_WORLD);
#else
	MPI_Send(&rpt, 1, MPI_INT, p->prot.nbor, 2, MPI_COMM_WORLD);
#endif
}

void RecvRepeat(ArgStruct *p, int *rpt)
{
	MPI_Status status;

	MPI_Recv(rpt, 1, MPI_INT, p->prot.nbor, 2, MPI_COMM_WORLD, &status);
}


int Establish(ArgStruct *p)
{
}

int  CleanUp(ArgStruct *p)
{
	MPI_Finalize();
}