00001 /*!@file Parallel/test-comm-master.C simple test 00002 to send and receive a float */ 00003 00004 // //////////////////////////////////////////////////////////////////// // 00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00006 // University of Southern California (USC) and the iLab at USC. // 00007 // See http://iLab.usc.edu for information about this project. // 00008 // //////////////////////////////////////////////////////////////////// // 00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00011 // in Visual Environments, and Applications'' by Christof Koch and // 00012 // Laurent Itti, California Institute of Technology, 2001 (patent // 00013 // pending; application number 09/912,225 filed July 23, 2001; see // 00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00015 // //////////////////////////////////////////////////////////////////// // 00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00017 // // 00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00019 // redistribute it and/or modify it under the terms of the GNU General // 00020 // Public License as published by the Free Software Foundation; either // 00021 // version 2 of the License, or (at your option) any later version. // 00022 // // 00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00026 // PURPOSE. See the GNU General Public License for more details. // 00027 // // 00028 // You should have received a copy of the GNU General Public License // 00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00031 // Boston, MA 02111-1307 USA. // 00032 // //////////////////////////////////////////////////////////////////// // 00033 // 00034 // Primary maintainer for this file: Christian Siagian <siagian@usc.edu> 00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Parallel/test-comm-master.C $ 00036 // $Id: test-comm-master.C 6393 2006-03-26 00:57:36Z rjpeters $ 00037 // 00038 00039 #include "Util/Types.H" 00040 //#include "Timer.H" 00041 #include "Beowulf/Beowulf.H" 00042 #include "Component/ModelManager.H" 00043 #include "Util/log.H" 00044 00045 #include <cstdio> 00046 #include <cstdlib> 00047 #include <signal.h> 00048 #include <unistd.h> 00049 00050 static bool goforever = true; 00051 void terminate(int s) 00052 { LERROR("*** INTERRUPT ***"); goforever = false; exit(1); } 00053 00054 // ###################################################################### 00055 /*! This simple program to send and receive a float */ 00056 int main(const int argc, const char **argv) 00057 { 00058 // instantiate a model manager: 00059 ModelManager manager("Communication Tester Master"); 00060 00061 // Instantiate our various ModelComponents: 00062 nub::soft_ref<Beowulf> 00063 beo(new Beowulf(manager, "Beowulf Master", "BeowulfMaster", true)); 00064 manager.addSubComponent(beo); 00065 00066 // Parse command-line: 00067 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1); 00068 00069 TCPmessage rmsg; // buffer to receive messages from nodes 00070 TCPmessage smsg; // buffer to send messages to nodes 00071 00072 // let's get all our ModelComponent instances started: 00073 manager.start(); 00074 00075 // catch signals and redirect them to terminate for clean exit: 00076 signal(SIGHUP, terminate); signal(SIGINT, terminate); 00077 signal(SIGQUIT, terminate); signal(SIGTERM, terminate); 00078 signal(SIGALRM, terminate); 00079 00080 // get ready for main loop: 00081 int32 rframe = 0, raction = 0, rnode = 0; 00082 00083 // this code is just for one slave for now 00084 //const int nbnode = beo->getNbSlaves(); // number of slave nodes 00085 00086 // send image to slave node, depending on frame number: 00087 smsg.reset(rframe, 1); 00088 smsg.addFloat(2.3434); 00089 beo->send(rnode, smsg); 00090 00091 int i = 1; 00092 while(goforever) 00093 { 00094 if(beo->receive(rnode, rmsg, rframe, raction, 5)) 00095 { 00096 float val = rmsg.getElementFloat(); 00097 LINFO("rec %f", val); 00098 rmsg.reset(rframe, raction); 00099 00100 sleep(1); 00101 smsg.reset(rframe, 1); 00102 smsg.addFloat(2.343412+i); 00103 beo->send(rnode,smsg); 00104 LINFO("send %f",2.343412+i); 00105 i++; 00106 } 00107 LINFO(" NOTHING"); 00108 } 00109 00110 // stop all our ModelComponents 00111 manager.stop(); 00112 00113 // all done! 00114 return 0; 00115 } 00116 00117 // ###################################################################### 00118 /* So things look consistent in everyone's emacs... */ 00119 /* Local Variables: */ 00120 /* indent-tabs-mode: nil */ 00121 /* End: */