| 1 |
/* |
| 2 |
* *************************************************************************** |
| 3 |
* MALOC = < Minimal Abstraction Layer for Object-oriented C > |
| 4 |
* Copyright (C) 1994-- Michael Holst |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 2.1 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this library; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 |
* |
| 20 |
* rcsid="$Id: vmpitst.c,v 1.14 2010/08/12 05:40:45 fetk Exp $" |
| 21 |
* *************************************************************************** |
| 22 |
*/ |
| 23 |
|
| 24 |
/* |
| 25 |
* *************************************************************************** |
| 26 |
* File: main.c |
| 27 |
* |
| 28 |
* Purpose: Test main driver for the VMPI layer. |
| 29 |
* |
| 30 |
* Author: Michael Holst 060197 |
| 31 |
* *************************************************************************** |
| 32 |
*/ |
| 33 |
|
| 34 |
#include <maloc/maloc.h> |
| 35 |
|
| 36 |
#define VEMBED(rctag) VPRIVATE const char* rctag; \ |
| 37 |
static void* use_rcsid=(0 ? &use_rcsid : (void*)&rcsid); |
| 38 |
VEMBED(rcsid="$Id: vmpitst.c,v 1.14 2010/08/12 05:40:45 fetk Exp $") |
| 39 |
|
| 40 |
int main(int argc, char *argv[]) |
| 41 |
{ |
| 42 |
/* |
| 43 |
* ************************************************************* |
| 44 |
* variables |
| 45 |
* ************************************************************** |
| 46 |
*/ |
| 47 |
|
| 48 |
/* mpi variables */ |
| 49 |
char buffer1, buffer2; |
| 50 |
int key; |
| 51 |
|
| 52 |
/* the mpi objects */ |
| 53 |
Vmpi *vmpi = VNULL; |
| 54 |
|
| 55 |
/* |
| 56 |
* ************************************************************* |
| 57 |
* mpi setup |
| 58 |
* ************************************************************** |
| 59 |
*/ |
| 60 |
|
| 61 |
/* construct the vmpi object */ |
| 62 |
VASSERT( Vmpi_init(&argc, &argv) ); |
| 63 |
vmpi = Vmpi_ctor(); |
| 64 |
|
| 65 |
/* setup -- root guy */ |
| 66 |
if (Vmpi_rank(vmpi) == 0) { |
| 67 |
fprintf(stderr,"<Process #%d (of %d) -- STARTUP(ROOT)>\n", |
| 68 |
Vmpi_rank(vmpi), Vmpi_size(vmpi)); |
| 69 |
buffer1 = 2; |
| 70 |
|
| 71 |
/* setup -- all non-root guys */ |
| 72 |
} else { |
| 73 |
fprintf(stderr,"<Process #%d (of %d) -- STARTUP(DRONE)>\n", |
| 74 |
Vmpi_rank(vmpi), Vmpi_size(vmpi)); |
| 75 |
} |
| 76 |
|
| 77 |
/* |
| 78 |
* ************************************************************* |
| 79 |
* computations... |
| 80 |
* ************************************************************** |
| 81 |
*/ |
| 82 |
|
| 83 |
/* send root guy's value to everyone; check to see that everyone got it */ |
| 84 |
key = 1; |
| 85 |
Vmpi_bcast(vmpi,&buffer1,key); |
| 86 |
if (buffer1 != 2) fprintf(stderr,"Problem!\n"); |
| 87 |
|
| 88 |
/* now add the broadcasted value up on every process */ |
| 89 |
key = 1; |
| 90 |
buffer2 = buffer1; |
| 91 |
Vmpi_reduce(vmpi,&buffer2,&buffer1,key); |
| 92 |
|
| 93 |
/* |
| 94 |
* ************************************************************* |
| 95 |
* mpi shutdown |
| 96 |
* ************************************************************** |
| 97 |
*/ |
| 98 |
|
| 99 |
/* cleanup -- root guy */ |
| 100 |
if (Vmpi_rank(vmpi) == 0) { |
| 101 |
/* default parameters */ |
| 102 |
|
| 103 |
/* finish up */ |
| 104 |
fprintf(stderr,"<Process #%d (of %d) -- SHUTDOWN(ROOT)>\n", |
| 105 |
Vmpi_rank(vmpi), Vmpi_size(vmpi)); |
| 106 |
fprintf(stderr,"<RESULT = %d>\n", buffer1); |
| 107 |
|
| 108 |
/* cleanup -- all non-root guys */ |
| 109 |
} else { |
| 110 |
fprintf(stderr,"<Process #%d (of %d) -- SHUTDOWN(DRONE)>\n", |
| 111 |
Vmpi_rank(vmpi), Vmpi_size(vmpi)); |
| 112 |
} |
| 113 |
|
| 114 |
/* keep everyone waiting here until root is ready */ |
| 115 |
Vmpi_barr(vmpi); |
| 116 |
|
| 117 |
/* destroy the vmpi object */ |
| 118 |
Vmpi_dtor(&vmpi); |
| 119 |
VASSERT( Vmpi_finalize() ); |
| 120 |
|
| 121 |
/* return */ |
| 122 |
return 0; |
| 123 |
} |
| 124 |
|