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: vmpitst.c,v 1.13 2008/03/12 05:14:00 fetk Exp $" 00021 * *************************************************************************** 00022 */ 00023 00024 /* 00025 * *************************************************************************** 00026 * File: main.c 00027 * 00028 * Purpose: Test main driver for the VMPI layer. 00029 * 00030 * Author: Michael Holst 060197 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: vmpitst.c,v 1.13 2008/03/12 05:14:00 fetk Exp $") 00039 00040 int main(int argc, char *argv[]) 00041 { 00042 /* 00043 * ************************************************************* 00044 * variables 00045 * ************************************************************** 00046 */ 00047 00048 /* mpi variables */ 00049 char buffer1, buffer2; 00050 int key; 00051 00052 /* the mpi objects */ 00053 Vmpi *vmpi = VNULL; 00054 00055 /* 00056 * ************************************************************* 00057 * mpi setup 00058 * ************************************************************** 00059 */ 00060 00061 /* construct the vmpi object */ 00062 VASSERT( Vmpi_init(&argc, &argv) ); 00063 vmpi = Vmpi_ctor(); 00064 00065 /* setup -- root guy */ 00066 if (Vmpi_rank(vmpi) == 0) { 00067 fprintf(stderr,"<Process #%d (of %d) -- STARTUP(ROOT)>\n", 00068 Vmpi_rank(vmpi), Vmpi_size(vmpi)); 00069 buffer1 = 2; 00070 00071 /* setup -- all non-root guys */ 00072 } else { 00073 fprintf(stderr,"<Process #%d (of %d) -- STARTUP(DRONE)>\n", 00074 Vmpi_rank(vmpi), Vmpi_size(vmpi)); 00075 } 00076 00077 /* 00078 * ************************************************************* 00079 * computations... 00080 * ************************************************************** 00081 */ 00082 00083 /* send root guy's value to everyone; check to see that everyone got it */ 00084 key = 1; 00085 Vmpi_bcast(vmpi,&buffer1,key); 00086 if (buffer1 != 2) fprintf(stderr,"Problem!\n"); 00087 00088 /* now add the broadcasted value up on every process */ 00089 key = 1; 00090 buffer2 = buffer1; 00091 Vmpi_reduce(vmpi,&buffer2,&buffer1,key); 00092 00093 /* 00094 * ************************************************************* 00095 * mpi shutdown 00096 * ************************************************************** 00097 */ 00098 00099 /* cleanup -- root guy */ 00100 if (Vmpi_rank(vmpi) == 0) { 00101 /* default parameters */ 00102 00103 /* finish up */ 00104 fprintf(stderr,"<Process #%d (of %d) -- SHUTDOWN(ROOT)>\n", 00105 Vmpi_rank(vmpi), Vmpi_size(vmpi)); 00106 fprintf(stderr,"<RESULT = %d>\n", buffer1); 00107 00108 /* cleanup -- all non-root guys */ 00109 } else { 00110 fprintf(stderr,"<Process #%d (of %d) -- SHUTDOWN(DRONE)>\n", 00111 Vmpi_rank(vmpi), Vmpi_size(vmpi)); 00112 } 00113 00114 /* keep everyone waiting here until root is ready */ 00115 Vmpi_barr(vmpi); 00116 00117 /* destroy the vmpi object */ 00118 Vmpi_dtor(&vmpi); 00119 VASSERT( Vmpi_finalize() ); 00120 00121 /* return */ 00122 return 0; 00123 } 00124