1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
40
#define SLAVENAME "slave"
41
#define SLAVENAME_CKPT "slave_ckpt"
43
int main(int argc, char **argv)
45
int mytid; /* my task id */
46
int tids[32]; /* slave task ids */
47
int n, nproc, numt, i, who, msgtype, nhost, narch;
48
float data[100], result[32];
49
struct pvmhostinfo *hostp[32];
51
printf("before pvm_mytid()\n"); fflush(stdout);
54
printf("pvm_mytid() = 0x%x\n", mytid); fflush(stdout);
56
/* Set number of slaves to start */
57
/* Can not do stdin from spawned task */
58
if( pvm_parent() == PvmNoParent ) {
59
printf("no parents\n"); fflush(stdout);
61
nproc = atoi(argv[1]);
64
puts("How many slave programs (1-32)?");
68
pvm_config( &nhost, &narch, hostp );
74
/* start up slave tasks */
75
printf("Try to spawn %d slaves\n", nproc); fflush(stdout);
76
numt=pvm_spawn(getenv("SGE_CKPT_ENV")?SLAVENAME_CKPT:SLAVENAME,
77
(char**)0, 0, "", nproc, tids);
79
printf("Trouble spawning slaves. Aborting. Error codes are:\n"); fflush(stdout);
80
for( i=numt ; i<nproc ; i++ ) {
81
printf("TID %d %d\n",i,tids[i]); fflush(stdout);
83
for( i=0 ; i<numt ; i++ ) {
90
printf("got %d tasks\n", numt); fflush(stdout);
92
/* Begin User Program */
94
/* initialize_data( data, n ); */
95
for( i=0 ; i<n ; i++ ) {
99
printf("broadcasting data to tasks\n"); fflush(stdout);
101
/* Broadcast initial data to slave tasks */
102
pvm_initsend(PvmDataDefault);
103
pvm_pkint(&nproc, 1, 1);
104
pvm_pkint(tids, nproc, 1);
106
pvm_pkfloat(data, n, 1);
107
while (pvm_mcast(tids, nproc, 0)) {
108
fprintf(stderr, "failure broadcasting data - retry\n");
112
printf("wait for results from slaves\n"); fflush(stdout);
114
/* Wait for results from slaves */
116
for( i=0 ; i<nproc ; i++ ) {
117
pvm_recv( -1, msgtype );
118
pvm_upkint( &who, 1, 1 );
119
pvm_upkfloat( &result[who], 1, 1 );
120
printf("I got %f from %d\n",result[who],who);
122
/* Program Finished exit PVM before stopping */