rosmpi.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * $Id: rosmpi.h 43069 2010-08-13 21:34:01Z rusu $
00035  *
00036  */
00037 #ifndef ROSMPI_H_
00038 #define ROSMPI_H_
00039 
00040 #include <boost/function.hpp>
00041 #include <boost/bind.hpp>
00042 #include <boost/make_shared.hpp>
00043 // ROS
00044 #include <ros/message.h>
00045 #include <ros/serialized_message.h>
00046 #include <ros/serialization.h>
00047 // OpenMPI
00048 #include <mpi.h>
00049 
00050 namespace rosmpi
00051 {
00053   namespace init_options
00054   {
00055     enum InitOption
00056     {
00058       ThreadSingle     = 0,
00060       ThreadFunneled   = 1,
00062       ThreadSerialized = 2,
00064       ThreadMultiple   = 3,
00065     };
00066   }
00067   typedef init_options::InitOption InitOption;
00068 
00074   void
00075     init (int &argc, char **argv, uint32_t options = 0)
00076   {
00077     // Initializes the MPI execution environment
00078     // If the process is multithreaded, only the thread that called MPI_Init_thread will make MPI calls
00079     int required = options;
00080     int ret = MPI::Init_thread (argc, argv, required);
00081     if (ret != required)
00082       ROS_WARN ("[rosmpi::init] MPI level of thread support required: %d, provided: %d.", required, ret);
00083 
00084     ros::Time::init ();
00085   }
00086 
00087   namespace this_processor
00088   {
00090     const std::string getName ()
00091     {
00092       int namelen;
00093       char processor_name[MPI_MAX_PROCESSOR_NAME];
00094       MPI::Get_processor_name (processor_name, namelen);
00095       return (std::string (processor_name));
00096     }
00097   }
00098 
00099   namespace communicator
00100   {
00102     int getSize ()
00103     {
00104       return (MPI::COMM_WORLD.Get_size ());
00105     }
00106 
00108     int getRank ()
00109     {
00110       return (MPI::COMM_WORLD.Get_rank ());
00111     }
00112   }
00113 
00114   void
00115     shutdown ()
00116   {
00117     // Terminates MPI execution environment
00118     MPI::Finalize ();
00119   }
00120 
00121   void
00122     spin ()
00123   {
00124     while (true)
00125     {
00126       usleep (10);
00127 
00128       // go over the vector of subscribers (which is the global queue) and call receive on each
00129     }
00130   }
00131 //  void
00132 //    spinOnce ()
00133 //  {
00134 //  }
00135 }
00136 
00137 #endif  //#ifndef ROSMPI_H_


rosmpi
Author(s): Radu Bogdan Rusu, John Hsu
autogenerated on Mon Jan 6 2014 11:27:20