- Main Page
- Namespaces
- Classes
- Files

- Search for |

# node.cpp

    00001 // "node.cpp"
    00002
    00003 // (c) OPAC Team, LIFL, August 2005
    00004
    00005 /*
    00006    Contact: paradiseo-help@lists.gforge.inria.fr
    00007 */
    00008
    00009 #include <mpi.h>
    00010 #include <vector>
    00011 #include <map>
    00012 #include <string>
    00013 #include <cassert>
    00014
    00015 static int rk, sz; /* Rank & size */
    00016
    00017 static std :: map <std :: string, int> name_to_rk;
    00018
    00019 static std :: vector <std :: string> rk_to_name;
    00020
    00021 int getNodeRank () {
    00022
    00023   return rk;
    00024 }
    00025
    00026 int getNumberOfNodes () {
    00027
    00028   return sz;
    00029 }
    00030
    00031 int getRankFromName (const std :: string & __name) {
    00032
    00033   return atoi (__name.c_str ());
    00034 }
    00035
    00036 void initNode (int * __argc, char * * * __argv) {
    00037
    00038   int provided;
    00039   MPI_Init_thread (__argc,  __argv, MPI_THREAD_FUNNELED, & provided);
    00040   assert (provided == MPI_THREAD_FUNNELED); /* The MPI implementation must be multi-threaded.
    00041                                                Yet, only one thread performs the comm.
    00042                                                operations */
    00043   MPI_Comm_rank (MPI_COMM_WORLD, & rk);   /* Who ? */
    00044   MPI_Comm_size (MPI_COMM_WORLD, & sz);    /* How many ? */
    00045
    00046   char names [sz] [MPI_MAX_PROCESSOR_NAME];
    00047   int len;
    00048
    00049   /* Processor names */
    00050   MPI_Get_processor_name (names [0], & len);   /* Me */
    00051   MPI_Allgather (names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, MPI_COMM_WORLD); /* Broadcast */
    00052
    00053   for (int i = 0; i < sz; i ++) {
    00054     rk_to_name.push_back (names [i]);
    00055     name_to_rk [names [i]] = i;
    00056   }
    00057 }
    00058