00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <maloc/maloc.h>
00035
00036 #define VEMBED(rctag) VPRIVATE const char* rctag; \
00037 static void* use_rcsid=(0 ? &use_rcsid : (void*)&rcsid);
00038 VEMBED(rcsid="$Id: vcomtst.c,v 1.12 2008/03/12 05:14:00 fetk Exp $")
00039
00040 int main(int argc, char *argv[]) {
00041
00042 int i, testi, testj;
00043 int myrank;
00044 int nproc;
00045 char string[100];
00046 Vcom *vcom;
00047
00048 VASSERT( Vcom_init(&argc,&argv) );
00049 vcom = Vcom_ctor(1);
00050 myrank = Vcom_rank(vcom);
00051 nproc = Vcom_size(vcom);
00052
00053 printf("PE %d: Starting test program with %d total PEs.\n",myrank,nproc);
00054
00055
00056 if (myrank == 0) {
00057 printf("\n\nPE %d: STARTING SEND/RECV TEST.\n",myrank);
00058 printf("PE %d: Sending non-blocked messages.\n",myrank);
00059 for (i=1; i<nproc; i++) {
00060 sprintf(&(string[0]), "non-blocked message (PE %d --> %d)",
00061 myrank, i);
00062 printf( "PE %d: Sent non-blocked message to PE %d\n", myrank, i);
00063 assert(Vcom_send(vcom,i,string,100,3,0));
00064 }
00065 printf("PE %d: Sending blocked messages.\n",myrank);
00066 for (i=1; i<nproc; i++) {
00067 sprintf(&(string[0]),"blocked message (PE %d --> %d)",i,nproc);
00068 printf( "PE %d: Sent blocked message to PE %d\n", myrank, i);
00069 assert(Vcom_send(vcom,i,string,100,3,1));
00070 }
00071 } else {
00072 printf("PE %d: Recving blocked message from PE 0.\n",myrank);
00073
00074 assert(Vcom_recv(vcom,0,string,100,3,1));
00075 printf( "PE %d: Blocked message is: '%s'\n",myrank,string);
00076
00077 printf("PE %d: Recving non-blocked message from PE 0.\n",myrank);
00078 assert(Vcom_recv(vcom,0,string,100,3,1));
00079 printf( "PE %d: Non-blocked message is: '%s'\n",myrank,string);
00080 }
00081 fflush(stdout);
00082 Vcom_barr(vcom);
00083
00084
00085 if (myrank == 0) printf("\n\nPE %d: STARTING BARRIER TEST.\n",myrank);
00086 printf("PE %d: Hit barrier\n", myrank);
00087 Vcom_barr(vcom);
00088 printf("PE %d: Passed barrier\n", myrank);
00089 fflush(stdout);
00090 Vcom_barr(vcom);
00091
00092
00093 if (myrank == 0) {
00094 printf("\n\nPE %d: STARTING PROBE TEST.\n",myrank);
00095 printf("PE %d: Sending string of length 100\n", myrank);
00096 for (i=1; i<nproc; i++) assert(Vcom_send(vcom,i,string,100,3,0));
00097 } else {
00098 Vcom_getCount(vcom, 0, &testi, 3);
00099 printf("PE %d: Probed for string of length %d\n", myrank, testi);
00100 }
00101 fflush(stdout);
00102 Vcom_barr(vcom);
00103
00104
00105 testi = 4;
00106 if (myrank == 0) {
00107 printf("\n\nPE %d: STARTING REDUCTION TEST.\n",myrank);
00108 printf("PE %d: All %d PEs have the number %d.\n", myrank, nproc, testi);
00109 printf("PE %d: Performing global sum reduction.\n", myrank);
00110 }
00111 Vcom_reduce(vcom, &testi, &testj, 1, 1, 0);
00112 printf("PE %d: Global sum = %d\n", myrank, testj);
00113 fflush(stdout);
00114 Vcom_barr(vcom);
00115 testi = 4;
00116 if (myrank == 0) {
00117 testj = 8;
00118 printf("PE %d: PE %d has the number %d; all others have %d.\n", myrank,
00119 myrank, testj, testi);
00120 testi = testj;
00121 printf("PE %d: Performing global max reduction.\n", myrank);
00122 }
00123 Vcom_reduce(vcom, &testi, &testj, 1, 1, 3);
00124 printf("PE %d: Global max = %d\n", myrank, testj);
00125 fflush(stdout);
00126 Vcom_barr(vcom);
00127
00128
00129 printf("PE %d: Resizing communicator from %d to %d.\n", myrank, nproc,
00130 (int)(nproc/2));
00131 Vcom_resize(vcom, (int)(nproc/2));
00132 myrank = Vcom_rank(vcom);
00133 if (Vcom_rank(vcom) != -1) printf("PE %d: Hello world from resized communicator\n", myrank);
00134 Vcom_barr(vcom);
00135
00136
00137 printf("PE %d: Exiting test program.\n",myrank);
00138 fflush(stdout);
00139 Vcom_dtor(&vcom);
00140 VASSERT( Vcom_finalize() );
00141
00142 return 0;
00143 }
00144