| 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: vcomtst.c,v 1.13 2010/08/12 05:40:45 fetk Exp $" |
| 21 |
* *************************************************************************** |
| 22 |
*/ |
| 23 |
|
| 24 |
/* |
| 25 |
* *************************************************************************** |
| 26 |
* File: vcomtst.c |
| 27 |
* |
| 28 |
* Purpose: Low-level test of MPI routines in vcom.c |
| 29 |
* |
| 30 |
* Author: Nathan Baker and Michael Holst |
| 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: vcomtst.c,v 1.13 2010/08/12 05:40:45 fetk Exp $") |
| 39 |
|
| 40 |
int main(int argc, char *argv[]) { |
| 41 |
|
| 42 |
int i, testi, testj; |
| 43 |
int myrank; |
| 44 |
int nproc; |
| 45 |
char string[100]; |
| 46 |
Vcom *vcom; |
| 47 |
|
| 48 |
VASSERT( Vcom_init(&argc,&argv) ); |
| 49 |
vcom = Vcom_ctor(1); |
| 50 |
myrank = Vcom_rank(vcom); |
| 51 |
nproc = Vcom_size(vcom); |
| 52 |
|
| 53 |
printf("PE %d: Starting test program with %d total PEs.\n",myrank,nproc); |
| 54 |
|
| 55 |
/* Character send/recv test */ |
| 56 |
if (myrank == 0) { |
| 57 |
printf("\n\nPE %d: STARTING SEND/RECV TEST.\n",myrank); |
| 58 |
printf("PE %d: Sending non-blocked messages.\n",myrank); |
| 59 |
for (i=1; i<nproc; i++) { |
| 60 |
sprintf(&(string[0]), "non-blocked message (PE %d --> %d)", |
| 61 |
myrank, i); |
| 62 |
printf( "PE %d: Sent non-blocked message to PE %d\n", myrank, i); |
| 63 |
assert(Vcom_send(vcom,i,string,100,3,0)); |
| 64 |
} |
| 65 |
printf("PE %d: Sending blocked messages.\n",myrank); |
| 66 |
for (i=1; i<nproc; i++) { |
| 67 |
sprintf(&(string[0]),"blocked message (PE %d --> %d)",i,nproc); |
| 68 |
printf( "PE %d: Sent blocked message to PE %d\n", myrank, i); |
| 69 |
assert(Vcom_send(vcom,i,string,100,3,1)); |
| 70 |
} |
| 71 |
} else { |
| 72 |
printf("PE %d: Recving blocked message from PE 0.\n",myrank); |
| 73 |
/* Get blocked sent messages */ |
| 74 |
assert(Vcom_recv(vcom,0,string,100,3,1)); |
| 75 |
printf( "PE %d: Blocked message is: '%s'\n",myrank,string); |
| 76 |
/* Get blocked sent messages */ |
| 77 |
printf("PE %d: Recving non-blocked message from PE 0.\n",myrank); |
| 78 |
assert(Vcom_recv(vcom,0,string,100,3,1)); |
| 79 |
printf( "PE %d: Non-blocked message is: '%s'\n",myrank,string); |
| 80 |
} |
| 81 |
fflush(stdout); |
| 82 |
Vcom_barr(vcom); |
| 83 |
|
| 84 |
/* Barrier test */ |
| 85 |
if (myrank == 0) printf("\n\nPE %d: STARTING BARRIER TEST.\n",myrank); |
| 86 |
printf("PE %d: Hit barrier\n", myrank); |
| 87 |
Vcom_barr(vcom); |
| 88 |
printf("PE %d: Passed barrier\n", myrank); |
| 89 |
fflush(stdout); |
| 90 |
Vcom_barr(vcom); |
| 91 |
|
| 92 |
/* getCount test */ |
| 93 |
if (myrank == 0) { |
| 94 |
printf("\n\nPE %d: STARTING PROBE TEST.\n",myrank); |
| 95 |
printf("PE %d: Sending string of length 100\n", myrank); |
| 96 |
for (i=1; i<nproc; i++) assert(Vcom_send(vcom,i,string,100,3,0)); |
| 97 |
} else { |
| 98 |
Vcom_getCount(vcom, 0, &testi, 3); |
| 99 |
printf("PE %d: Probed for string of length %d\n", myrank, testi); |
| 100 |
} |
| 101 |
fflush(stdout); |
| 102 |
Vcom_barr(vcom); |
| 103 |
|
| 104 |
/* Reduction test */ |
| 105 |
testi = 4; |
| 106 |
if (myrank == 0) { |
| 107 |
printf("\n\nPE %d: STARTING REDUCTION TEST.\n",myrank); |
| 108 |
printf("PE %d: All %d PEs have the number %d.\n", myrank, nproc, testi); |
| 109 |
printf("PE %d: Performing global sum reduction.\n", myrank); |
| 110 |
} |
| 111 |
Vcom_reduce(vcom, &testi, &testj, 1, 1, 0); |
| 112 |
printf("PE %d: Global sum = %d\n", myrank, testj); |
| 113 |
fflush(stdout); |
| 114 |
Vcom_barr(vcom); |
| 115 |
testi = 4; |
| 116 |
if (myrank == 0) { |
| 117 |
testj = 8; |
| 118 |
printf("PE %d: PE %d has the number %d; all others have %d.\n", myrank, |
| 119 |
myrank, testj, testi); |
| 120 |
testi = testj; |
| 121 |
printf("PE %d: Performing global max reduction.\n", myrank); |
| 122 |
} |
| 123 |
Vcom_reduce(vcom, &testi, &testj, 1, 1, 3); |
| 124 |
printf("PE %d: Global max = %d\n", myrank, testj); |
| 125 |
fflush(stdout); |
| 126 |
Vcom_barr(vcom); |
| 127 |
|
| 128 |
/* Resize the communicator */ |
| 129 |
printf("PE %d: Resizing communicator from %d to %d.\n", myrank, nproc, |
| 130 |
(int)(nproc/2)); |
| 131 |
Vcom_resize(vcom, (int)(nproc/2)); |
| 132 |
myrank = Vcom_rank(vcom); |
| 133 |
if (Vcom_rank(vcom) != -1) printf("PE %d: Hello world from resized communicator\n", myrank); |
| 134 |
Vcom_barr(vcom); |
| 135 |
|
| 136 |
/* Finish up */ |
| 137 |
printf("PE %d: Exiting test program.\n",myrank); |
| 138 |
fflush(stdout); |
| 139 |
Vcom_dtor(&vcom); |
| 140 |
VASSERT( Vcom_finalize() ); |
| 141 |
|
| 142 |
return 0; |
| 143 |
} |
| 144 |
|