File: PVM.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 (206 lines) | stat: -rw-r--r-- 7,008 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*****************************************************************************/
/* "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.   */
/*                                                                           */
/*     * PVM.c              ---- PVM calls source                            */
/*****************************************************************************/
#include    "netpipe.h"
#include    <pvm3.h>

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

/**********************************************************************/
/* Set up the communcations system.                                   */
/*    In pvm, this means to join the parallel machine                 */
/**********************************************************************/
int
Setup(ArgStruct *p)
{
    p->prot.mytid = pvm_mytid();
#ifdef DEBUG
    printf("My task id is %d \n",p->prot.mytid);
#endif
}   

/**********************************************************************/
/* Establish a link with the other processor                          */
/*    In pvm, this means to send a simple message, but to keep the    */
/*    communication line open.  Since the assumption is that we are   */
/*    starting it by hand on the other machine, we don't know what    */
/*    the other task id is.                                           */
/**********************************************************************/
int
Establish(ArgStruct *p)
{
    /* Task information for the entire parallel machine (if trans) */
    int                     tasks_status;
    struct pvmtaskinfo      *taskp;
    int                     ntasks;

        /* Received buffer (if receiver)  */
    int buffer_id;

    /*
    If we are the transmitting side, go find the other one and send
    it a message containing our tid. If we are the receiving side,
    just wait for a message.
    */
    if ( p->tr ) {
#ifdef DEBUG
	printf("this is the transmitter\n");
#endif
	tasks_status = pvm_tasks( 0, &ntasks, &taskp );
	if ( ntasks != 2 ) {
	    printf("Error, too many processes in parallel machine \n");
	    printf("Start a clean machine.  n=%d\n", ntasks);
	    exit(-1);
	}

	/* Since there are two tasks, one is ours the other is the receiver */
	p->prot.othertid = -1;
	if ( taskp[0].ti_tid == p->prot.mytid ) {
	    p->prot.othertid = taskp[1].ti_tid;
	}
	if ( taskp[1].ti_tid == p->prot.mytid ) {
	    p->prot.othertid = taskp[0].ti_tid;
	}
	if ( p->prot.othertid == -1 ) {
	    printf("Error, cannot find other (receiving) task \n");
	    printf("Id's:  %d %d  \n",taskp[0].ti_tid,taskp[1].ti_tid);
	}

	/* Send the receiver a message.  Tell pvm to keep the channel open */

#ifdef DEBUG
	printf("The receiver tid is %d \n",p->prot.othertid);
#endif
	pvm_setopt( PvmRoute, PvmRouteDirect );
	pvm_initsend( PVMDATA );
	pvm_pkint( &p->prot.mytid, 1, 1 );
	pvm_send( p->prot.othertid, 1 );
    } else {
#ifdef DEBUG
	printf("This is the receiver \n");
#endif
                
	/* Receive any message from any task */
	buffer_id = pvm_recv(-1, -1);

	if ( buffer_id < 0 ) {
	    printf("Error on receive in receiver\n");
	    exit(-1);
	}
	pvm_upkint( &p->prot.othertid, 1, 1 );
    }
}

/**********************************************************************/
/* Prepare to receive                                                 */
/*    In pvm, you cannot set up a reception buffer ahead of time      */
/**********************************************************************/
void
PrepareToReceive(ArgStruct *p)
{
}

/**********************************************************************/
/* Synchronize                                                        */
/*     In pvm, this is not necessary                                  */
/**********************************************************************/
void
Sync(ArgStruct *p)
{
}

/**********************************************************************/
/* Send a buffer full of information                                  */
/*    In pvm, we use pvm_pkbyte and then send it.                     */
/**********************************************************************/
void
SendData(ArgStruct *p)
{
#ifdef DEBUG
    printf(" In send \n");
#endif
    pvm_initsend( PVMDATA );
    pvm_pkbyte( p->buff, p->bufflen, 1 );
    pvm_send( p->prot.othertid, 1 );
#ifdef DEBUG
    printf(" message sent.  Size=%d\n",p->bufflen);
#endif
}

/**********************************************************************/
/* Receive a buffer full of information                               */
/**********************************************************************/
void
RecvData(ArgStruct *p)
{
#ifdef DEBUG
    printf(" In receive \n");
#endif
    pvm_recv( -1, -1);
    pvm_upkbyte( p->buff, p->bufflen, 1);
#ifdef DEBUG
    printf(" message received .  Size=%d \n", p->bufflen);
#endif
}

/**********************************************************************/
/* Send elapsed time to the other process                             */
/**********************************************************************/
void
SendTime(ArgStruct *p, double *t)
{
    pvm_initsend( PVMDATA );
    pvm_pkdouble( t, 1, 1 );
    pvm_send( p->prot.othertid, 1);
}

/**********************************************************************/
/* Receive elapsed time from the other process                        */
/**********************************************************************/
void
RecvTime(ArgStruct *p, double *t)
{
    pvm_recv(-1, -1);
    pvm_upkdouble( t, 1, 1 );
}

/**********************************************************************/
/* Send repeat count to the other process                             */
/**********************************************************************/
void
SendRepeat(ArgStruct *p, int rpt)
{
    pvm_initsend( PVMDATA );
    pvm_pkint( &rpt, 1, 1 );
    pvm_send( p->prot.othertid, 1);
}

/**********************************************************************/
/* Receiver repeat count from other process                           */
/**********************************************************************/
void
RecvRepeat(ArgStruct *p, int *rpt)
{
    pvm_recv(-1, -1);
    pvm_upkint( rpt, 1, 1 );
}

/**********************************************************************/
/* Close down the connection.
/**********************************************************************/
int
CleanUp(ArgStruct *p)
{
}