• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

contrib/maloc/tools/tests/psh/vcomtst.c

00001 /*
00002  * ***************************************************************************
00003  * MALOC = < Minimal Abstraction Layer for Object-oriented C >
00004  * Copyright (C) 1994--2008 Michael Holst
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019  *
00020  * rcsid="$Id: vcomtst.c,v 1.12 2008/03/12 05:14:00 fetk Exp $"
00021  * ***************************************************************************
00022  */
00023 
00024 /*
00025  * ***************************************************************************
00026  * File:     vcomtst.c
00027  *
00028  * Purpose:  Low-level test of MPI routines in vcom.c
00029  *
00030  * Author:   Nathan Baker and Michael Holst
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     /* Character send/recv test */
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         /* Get blocked sent messages */
00074         assert(Vcom_recv(vcom,0,string,100,3,1));
00075         printf( "PE %d: Blocked message is: '%s'\n",myrank,string);
00076         /* Get blocked sent messages */
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     /* Barrier test */
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     /* getCount test */
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     /* Reduction test */
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     /* Resize the communicator */
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     /* Finish up */
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 

Generated on Wed Oct 20 2010 11:12:15 for APBS by  doxygen 1.7.2