node.cpp

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 // "node.cpp"
00004 
00005 // (c) OPAC Team, LIFL, August 2005
00006 
00007 /* This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011    
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016    
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with this library; if not, write to the Free Software
00019    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020    
00021    Contact: paradiseo-help@lists.gforge.inria.fr
00022 */
00023 
00024 #include <mpi.h>
00025 #include <vector>
00026 #include <map>
00027 #include <string>
00028 #include <cassert>
00029 
00030 static int rk, sz; /* Rank & size */
00031 
00032 static std :: map <std :: string, int> name_to_rk;
00033 
00034 static std :: vector <std :: string> rk_to_name;
00035 
00036 int getNodeRank () {
00037 
00038   return rk;
00039 }
00040 
00041 int getNumberOfNodes () {
00042 
00043   return sz;
00044 }
00045 
00046 int getRankFromName (const std :: string & __name) {
00047   
00048   return atoi (__name.c_str ());  
00049 }
00050 
00051 void initNode (int * __argc, char * * * __argv) {
00052   
00053   int provided;
00054   MPI_Init_thread (__argc,  __argv, MPI_THREAD_FUNNELED, & provided);  
00055   assert (provided == MPI_THREAD_FUNNELED); /* The MPI implementation must be multi-threaded.
00056                                                Yet, only one thread performs the comm.
00057                                                operations */
00058   MPI_Comm_rank (MPI_COMM_WORLD, & rk);   /* Who ? */
00059   MPI_Comm_size (MPI_COMM_WORLD, & sz);    /* How many ? */
00060 
00061   char names [sz] [MPI_MAX_PROCESSOR_NAME];
00062   int len;
00063 
00064   /* Processor names */ 
00065   MPI_Get_processor_name (names [0], & len);   /* Me */  
00066   MPI_Allgather (names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, MPI_COMM_WORLD); /* Broadcast */
00067   
00068   for (int i = 0; i < sz; i ++) {
00069     rk_to_name.push_back (names [i]);
00070     name_to_rk [names [i]] = i;
00071   }
00072 }
00073 

Generated on Wed Dec 20 13:45:48 2006 for ParadisEO by  doxygen 1.4.6