Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsPvmGlobalController.cxx

Go to the documentation of this file.
00001 /*
00002  * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software
00003  * 
00004  * The Software has been developped within the Siames Project. 
00005  * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights
00006  * 
00007  * The Software has been registered with the Agence pour la Protection des
00008  * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200
00009  *  
00010  * This file may be distributed under the terms of the Q Public License
00011  * version 1.0 as defined by Trolltech AS of Norway and appearing in the file
00012  * LICENSE.QPL included in the packaging of this file.
00013  *
00014  * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 
00015  * for the software may use this file in accordance with that specific license
00016  *
00017  */
00018 #ifdef _PVM
00019 #include <sys/time.h>
00020 #include <PsPvmGlobalController.h>
00021 #include <PsnPvmSvm.h>
00022 #include <unistd.h>
00023 
00024 //----------------------------------------------------------------------------------
00025 
00026 PsPvmGlobalController::PsPvmGlobalController (PsObjectDescriptor & scenario,
00027                                               const PsDate & initialDate,
00028                                               PsNameToPointerMap<PsnProcess> * tab,
00029                                               const PsString & fConfig,
00030                                               const PsDate & latence)
00031   : PsController (scenario, initialDate) {
00032    // demarrage de la machine virtuelle Siames
00033    //************************
00034    // mise en oeuvre PVM
00035    //************************
00036    laSVM =  new PsnPvmSvm (tab, latence) ;
00037    // initialisation de la machine virtuelle
00038    cout << "Initialisation du reseau........................" << endl;
00039    // en attendant que les PsStrings fonctionnent effectivement ...
00040 //     char buff [256] ;
00041 //     ostrstream os (buff, 256) ;
00042 //     os << fConfig.getCString () << " " << latence << '\0' ;
00043    PsString fConfigue (fConfig) ;
00044    PsString espace(" ");
00045    //7 fev 1999 : utilisation des PsStrings qui marchent (si on sait s'en servir)
00046    fConfigue=fConfigue+espace+latence+espace;
00047    //7/02/1999 : ajout du repertoire de travail dans les options du PVM_LOCAL
00048    fConfigue=fConfigue+getenv("PWD")+"/";
00049    cout << "fConfigue = " << fConfigue << endl ;
00050    laSVM->init (fConfigue, initialDate) ;
00051    // On recupere le pid de ce pss
00052    // pidCG = getpid () ;
00053    // On commence
00054 }
00055 
00056 //----------------------------------------------------------------------------------
00057 
00058 PsPvmGlobalController::~PsPvmGlobalController () {
00059    laSVM->stop () ;
00060    delete laSVM ;
00061 }
00062 
00063 
00064 
00065 //----------------------------------------------------------------------------------
00066 
00067 void PsPvmGlobalController::run () {
00068    PsFrequency freqGlobale ;
00069    //PsnPvmIncomingMessage * message ;
00070 
00071    struct timeval wallTimeAtStart ;
00072    struct timeval wallTimeAtEnd ;
00073    struct timeval wallTimeSimulationLength ;
00074 
00075 #ifdef INFO
00076    cout << endl << "Synchronisation globale........................." << endl ;
00077 #endif
00078    freqGlobale = laSVM->synchroGlobale () ;
00079 #ifdef INFO
00080    cout << endl << "Execution du controleur global.................." << endl ;
00081 #endif
00082    laSVM->surveillerSynchroCL () ;
00083    //cerr << "PsPvmGlobalController::run : synchro reception avant boucle init" << endl ;
00084    laSVM->envoyerTopCL () ;
00085    //cerr << "PsPvmGlobalController::run : synchro emission avant boucle init" << endl ;
00086    laSVM->surveillerSynchroCL () ;
00087    //cerr << "PsPvmGlobalController::run : synchro reception apres boucle init" << endl ;
00088    laSVM->envoyerTopCL () ;
00089    //cerr << "PsPvmGlobalController::run : synchro emission apres boucle init" << endl ;
00090    cerr<<"Tous les processus sont initialisés et partis"<<endl;
00091    // On recupere le temps du debut de la simulation
00092    gettimeofday (&wallTimeAtStart, NULL) ;
00093          // On met a jour la fin de la simulation
00094    laSVM->surveillerSynchroCL () ;
00095 
00096    gettimeofday (&wallTimeAtEnd, NULL) ;
00097    // On calcule la wallTimeSimulationLength de temps depuis le debut
00098    if (wallTimeAtEnd.tv_usec >= wallTimeAtStart.tv_usec) {
00099       wallTimeSimulationLength.tv_sec = wallTimeAtEnd.tv_sec - wallTimeAtStart.tv_sec;
00100       wallTimeSimulationLength.tv_usec = wallTimeAtEnd.tv_usec - wallTimeAtStart.tv_usec;
00101    } else {
00102       wallTimeSimulationLength.tv_sec = wallTimeAtEnd.tv_sec - wallTimeAtStart.tv_sec - 1;
00103       // Une seconde correspond a 1000000 microseconde eh oui ;-D
00104       wallTimeSimulationLength.tv_usec = 1000000 - wallTimeAtStart.tv_usec + wallTimeAtEnd.tv_usec;
00105    }
00106    // On affiche la derive par rapport au temps
00107    cerr << "-------------------------------------" << endl
00108         << "Duree effective : " << wallTimeSimulationLength.tv_sec
00109         << " s " << wallTimeSimulationLength.tv_usec << endl ;
00110 #ifdef INFO
00111    cout << endl << "Fin du controleur global........................" << endl ;
00112 #endif
00113 }
00114 
00115 #endif

logo OpenMask

Documentation generated on Mon Nov 25 15:25:02 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001