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 //-------------------------------------------------------------- 00019 // Ce programme demarre la plateforme directement depuis 00020 // un controleur local qui sera seul dans la simulation. 00021 // Tous les objets de simulation seront des referentiels 00022 // Les communications reseau ne seront pas necessaires. 00023 // 00024 // Un argument a la commande versMonoProc 00025 // 1: nom du fichier de configuraton 00026 // 00027 // A. Chauffaut 00028 // 6 Septembre 1996 00029 //-------------------------------------------------------------- 00030 #include <PsNameServer.h> 00031 #include <stdlib.h> 00032 #include <iostream> 00033 #include <sys/types.h> 00034 #include <unistd.h> 00035 #include <math.h> 00036 #include <PsController.h> 00037 #include "PsMultiThreadedController.h" 00038 #include <PsnTimerControleur.h> 00039 #include <PsKernelObjectAbstractFactory.h> 00040 #ifdef _PSGUI1 00041 #include <PsnGuiController.h> 00042 #include <ilviews/ilm.h> 00043 static char *ilm_license=\ 00044 "LICENSE inria-rennes-application Mask\n\ 00045 RUNTIME Views 3.110 NEVER R43GC3WSWGFS Y irix5 "; 00046 static int ilm_license_signature=2918071; 00047 #endif 00048 #ifdef _PVM 00049 #include <PsPvmController.h> 00050 #include <PsnBenchControleurPVM.h> 00051 #include <PsPvmControllerGlobal.h> 00052 #endif 00053 #ifdef _SGI 00054 #include <PsnBenchControleur.h> 00055 #include <PsRealTimeController.h> 00056 #endif 00057 #include <PsMonoProcessController.h> 00058 #ifdef _REACT 00059 #include <PsReactGlobalController.h> 00060 #endif 00061 #ifdef _MOME 00062 #include "PsMomeMultiThreadedController.h" 00063 #include <PsMomeController.h> 00064 #include <mySharedAllocator.h> 00065 #include <MomeDsm.h> 00066 #include <PsnNew.h> 00067 #endif 00068 #ifdef _SGI 00069 #include <simFile.h> 00070 #include <testFormat.h> 00071 #include <PsArbreSimulV3.h> 00072 #endif 00073 #include <stdlib.h> 00074 #include <stdio.h> 00075 #include <iostream> 00076 #include <string> 00077 #include <PsException.h> 00078 00079 char * nomExecutable = "rien" ; 00080 bool testSG3(const char *fName) 00081 //Honteusement copié de testFormat.cxx de simulV3 écrit par Guillaume Moreau 00082 { 00083 FILE * f = fopen (fName, "r") ; 00084 if (f == NULL) { 00085 // en cas d'échec, on se place dans le répertoire qui va bien 00086 //PsString workingDir = ("${HOME}/pvm3/bin/$PVM_ARCH") ; 00087 PsString nomFich = getenv ("HOME") ; 00088 nomFich = nomFich + "/pvm3/bin/" + getenv ("PVM_ARCH") + "/" 00089 + PsString (fName) ; 00090 f = fopen (nomFich.getCString (), "r") ; 00091 if (f == NULL) { 00092 cerr << "impossible d'ouvrir le fichier " << fName << " ou " << nomFich << endl ; 00093 exit(-1) ; 00094 } 00095 } 00096 // vérification de l'entête 00097 char tmp[200]; 00098 fread(tmp,1,5,f); 00099 tmp[5] = 0x0; 00100 if (strcmp(tmp,"//sG3")) 00101 { 00102 fclose(f); 00103 return false; 00104 } 00105 fclose(f); 00106 return true; 00107 } 00108 00109 PsString nomPVM (const PsString fName) { 00110 PsString nom = fName ; 00111 FILE * f = fopen (fName.getCString (), "r") ; 00112 if (f == NULL) { 00113 // en cas d'échec, on se place dans le répertoire qui va bien 00114 //PsString workingDir = ("${HOME}/pvm3/bin/$PVM_ARCH") ; 00115 PsString nomFich = getenv ("HOME") ; 00116 nomFich = nomFich + "/pvm3/bin/" + getenv ("PVM_ARCH") + "/" 00117 + fName ; 00118 f = fopen (nomFich.getCString (), "r") ; 00119 if (f != NULL) { 00120 nom = nomFich ; 00121 } else { 00122 cerr << "nomPVM : impossible d'ouvrir le fichier " << fName << endl ; 00123 } 00124 } 00125 return nom ; 00126 } 00127 00128 void usage() 00129 { 00130 cerr<< "usage: versMonoProc nomFichierConfig [option]"<<endl 00131 << " avec option= GUI | Bench [nomFichier] | PVM [latence]" 00132 #ifdef _REACT 00133 <<"|React [nbProc]"<<endl 00134 <<"avec nbProc entre 1 et nombre de processeur de la machine moins 1" 00135 #endif 00136 <<endl; 00137 exit(1); 00138 } 00139 00140 #include <PsArbreSimul.h> 00141 #include <PsController.h> 00142 #include <PsString.h> 00143 00144 void openMaskMain (int argc, char *argv[]) 00145 { 00146 if (argc < 2) 00147 { 00148 usage(); 00149 } 00150 else 00151 { 00152 // acquisition du scenario 00153 // le nom du fichier de configuration est le premier argument 00154 // de la commande 00155 PsString fConfig= argv[1]; 00156 if (fConfig.findCaracter('/')!=0) {//On a un nom de fichier relatif : c'est un problème pour PVM 00157 if (argc>=3) { 00158 PsString option1=argv[2]; 00159 if ((option1=="PVM_LOCAL")||(option1=="PVM_LOCAL_BENCH")) { 00160 PsString chemin=argv[4]; 00161 chemin=chemin+fConfig; 00162 // fConfig=chemin; 00163 } 00164 } 00165 } 00166 // ctest<< "fichier de configuration = " << fConfig<< endl; 00167 00168 #ifdef MAIN_FICHIER 00169 // Fichier pour connaitre la ligne de commande en fonction du PID 00170 char nomFic[80]; 00171 sprintf(nomFic, "fichierPID%d", getpid()); 00172 ofstream fichierPID; 00173 fichierPID.open(nomFic); 00174 fichierPID << argv[0] << " " << argv[1] << endl; 00175 fichierPID.close(); 00176 #endif 00177 // Init du serveur de nom 00178 PsName::serveurDeNom = new PsNameServerClassique(1); 00179 00180 // Construction de l'arbre de simulation 00181 PsSimulationNAryTree *scenario; 00182 // Construction de la table des processus (pour PVM) 00183 PsNameToPointerMap<PsnProcess> * table = NULL ; 00184 // modif GM pour intégrer les arbres de simul sG3 00185 PsArbreSimul *t =NULL; 00186 if (testSG3(fConfig.getCString())) 00187 { 00188 ctest << "fichier de configuration de type sG3" << endl; 00189 #ifdef _SGI 00190 simFile *a = simParse(nomPVM (fConfig).getCString ()) ; 00191 PsArbreSimulV3 *t = new PsArbreSimulV3(a); 00192 scenario = t->arbreSimulation(); 00193 table = t->TableProcessus () ; 00194 #endif 00195 } 00196 00197 else 00198 { 00199 t = new PsArbreSimul(nomPVM (fConfig).getCString (), argv[0]); 00200 scenario = t->arbreSimulation(); 00201 table = t->TableProcessus () ; 00202 } 00203 00204 // Initialisation du display avec la variable systeme 00205 const char* displayX11= getenv("DISPLAY"); 00206 00207 //construction du bon controleur local 00208 PsController * ctrlLocal; 00209 if (argc==2) { 00210 cout<<"Simulation sans GUI"<<endl; 00211 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00212 ctrlLocal = new PsController("MonoProc", scenario,aKernelObjectFactory); 00213 } 00214 else { //plus d'un argument 00215 PsString option=argv[2]; 00216 #ifdef _PSGUI1 00217 if (option=="GUI") { 00218 //cout<<"Licence run-time Ilog views"<<endl; 00219 if(IlvRegisterLicense(ilm_license, ilm_license_signature)) { 00220 cerr<<"Impossible de touver la licence run-time"<<endl; 00221 exit(-1); 00222 } 00223 cout<<"Simulation avec GUI"<<endl; 00224 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00225 ctrlLocal = new PsnGuiController("MonoProc", scenario, aKernelObjectFactory); 00226 if (argc==4){ 00227 // acquisition du nom de display fourni 00228 // comme argument de la commande unix 00229 cout<<"Définition d'un display spécifique: "<<argv[3]<<endl; 00230 displayX11= argv[3]; 00231 } 00232 00233 } else 00234 #endif 00235 #ifdef _PVM 00236 if (option=="PVM") { 00237 cout << "Simulation PVM globale avec latence = " ; 00238 PsString fConfigPVM = argv[1] ; 00239 fConfigPVM = fConfigPVM + " PVM_LOCAL" ; 00240 //fConfig = fConfig + " PVM_LOCAL" ; 00241 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00242 if (argc == 4) { 00243 istrstream is (argv [3]) ; 00244 int latence ; 00245 is >> latence ; 00246 cout << latence << " millisecondes" << endl ; 00247 ctrlLocal = new PsPvmControllerGlobal ("PVM", 00248 scenario, 00249 table, 00250 aKernelObjectFactory, 00251 fConfigPVM, 00252 PsDate (latence)) ; 00253 } else { 00254 cout << "valeur par defaut" << endl ; 00255 ctrlLocal = new PsPvmControllerGlobal ("PVM", 00256 scenario, 00257 table, 00258 aKernelObjectFactory, 00259 fConfigPVM) ; 00260 } 00261 } else 00262 if (option=="PVMBench") { 00263 cout << "Simulation PVM globale avec latence = " ; 00264 fConfig = fConfig + " PVM_LOCAL_BENCH" ; 00265 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00266 if (argc == 4) { 00267 istrstream is (argv [3]) ; 00268 int latence ; 00269 is >> latence ; 00270 cout << latence << " millisecondes" << endl ; 00271 cout<<"Et mesure des performances"<<endl; 00272 ctrlLocal = new PsPvmControllerGlobal ("PVM", scenario, table, aKernelObjectFactory,fConfig, PsDate (latence)) ; 00273 } else { 00274 cout << "valeur par defaut" << endl ; 00275 ctrlLocal = new PsPvmControllerGlobal ("PVM", scenario, table, aKernelObjectFactory, fConfig) ; 00276 } 00277 } else 00278 if (option=="PVM_LOCAL") { 00279 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00280 istrstream is (argv [3]) ; 00281 int latence ; 00282 is >> latence ; 00283 cout << "Simulation PVM locale avec latence = " << latence << " millisecondes" << endl ; 00284 ctrlLocal = new PsPvmController ("PVM_LOCAL", 00285 scenario, 00286 table, 00287 aKernelObjectFactory, 00288 PsDate (latence), 00289 PsString (argv[4])) ; 00290 } else 00291 if (option=="PVM_LOCAL_BENCH") { 00292 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00293 istrstream is (argv [3]) ; 00294 int latence ; 00295 is >> latence ; 00296 cout << "Simulation PVM Bench locale avec latence = " << latence << " millisecondes" << endl ; 00297 ctrlLocal = new PsnBenchControleurPVM ("PVM_LOCAL", 00298 scenario, 00299 table, 00300 aKernelObjectFactory, 00301 PsDate (latence), 00302 PsString(argv[4])) ; 00303 } else 00304 #endif 00305 #ifdef _REACT 00306 if (option=="React") { 00307 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00308 if (argc==4) { 00309 cout<<"Simulation React/pro avec "<<argv[3]<<" processeurs"<<endl; 00310 ctrlLocal = new PsReactGlobalController(argv[3], scenario,aKernelObjectFactory); 00311 } 00312 else { 00313 cout<<"Simulation React/pro avec 1 processeur"<<endl; 00314 ctrlLocal = new PsReactGlobalController("1",scenario,aKernelObjectFactory); 00315 } 00316 } 00317 else 00318 #endif 00319 if (option=="Timed") { 00320 cout<<"Simulation avec chronometrage"<<endl; 00321 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00322 ctrlLocal = new PsnTimerControleur < PsMonoProcessController > ("MonoProc",scenario,aKernelObjectFactory); 00323 } 00324 else 00325 #ifdef _SGI 00326 if (option=="RealTime") { 00327 cout<<"Real Time Simulation if enough processing power is available"<<endl; 00328 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00329 ctrlLocal = new PsRealTimeController("MonoProc",scenario,aKernelObjectFactory); 00330 } 00331 else 00332 if (option=="Bench") { 00333 cout<<"Simulation avec benchmark produit"; 00334 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00335 if (argc==4) { 00336 cout<<" dans le fichier "<<argv[3]<<endl; 00337 ctrlLocal = new PsnBenchControleur("MonoProc",scenario,aKernelObjectFactory,argv[3]); 00338 } 00339 else { 00340 cout<<" sur la output standard "<<endl; 00341 ctrlLocal = new PsnBenchControleur("MonoProc",scenario,aKernelObjectFactory,""); 00342 } 00343 } 00344 else 00345 #endif 00346 #ifdef _MOME 00347 if (option=="MomeMulti") { 00348 assert(argc >= 4) ; 00349 aKernelObjectFactory= new PsKernelObjectMomeFactory(); 00350 MomeInit(argc,argv); 00351 PsNameToPointerMap<PsnProcess>::const_iterator ii=table->begin(); 00352 for (int cpt=0; cpt<MomeMe; cpt++) { 00353 ii++; 00354 } 00355 if(ii!=table->end()) { 00356 ctrlLocal = new PsMomeMultiThreadedController((*ii).first, 00357 scenario, 00358 aKernelObjectFactory, 00359 atoi(argv[3]) ); 00360 } 00361 } 00362 else 00363 if (option=="MomeMultiTimed") { 00364 assert(argc >= 4) ; 00365 aKernelObjectFactory= new PsKernelObjectMomeFactory(); 00366 MomeInit(argc,argv); 00367 PsNameToPointerMap<PsnProcess>::const_iterator ii=table->begin(); 00368 for (int cpt=0; cpt<MomeMe; cpt++) { 00369 ii++; 00370 } 00371 if(ii!=table->end()) { 00372 cerr<<"Construction du controleur Mome de nom "<<(*ii).first<<endl; 00373 ctrlLocal = new PsnTimerControleur<PsMomeMultiThreadedController>((*ii).first, 00374 scenario, 00375 aKernelObjectFactory, 00376 atoi(argv[3]) ); 00377 } 00378 } 00379 else 00380 if (option=="MomeTimed") { 00381 cout<<"Simulation lancée sur Mome"<<endl;; 00382 aKernelObjectFactory= new PsKernelObjectMomeFactory(); 00383 cout<<"Initialisation de la Mome"<<endl; 00384 MomeInit(argc,argv); 00385 PsNameToPointerMap<PsnProcess>::const_iterator ii=table->begin(); 00386 for (int cpt=0; cpt<MomeMe; cpt++) { 00387 ii++; 00388 } 00389 if(ii!=table->end()) { 00390 cerr<<"Construction du controleur Mome de nom "<<(*ii).first<<endl; 00391 ctrlLocal = new PsnTimerControleur<PsMomeController>((*ii).first, 00392 scenario, 00393 aKernelObjectFactory); 00394 } 00395 } 00396 00397 else 00398 if (option=="Mome") { 00399 nomExecutable = argv[0] ; 00400 cout<<"Simulation lancée sur Mome"<<endl;; 00401 aKernelObjectFactory= new PsKernelObjectMomeFactory(); 00402 cout<<"Initialisation de la Mome"<<endl; 00403 MomeInit(argc,argv); 00404 PsNameToPointerMap<PsnProcess>::const_iterator ii=table->begin(); 00405 for (int cpt=0; cpt<MomeMe; cpt++) { 00406 ii++; 00407 } 00408 if(ii!=table->end()) { 00409 cerr<<"Construction du controleur Mome de nom "<<(*ii).first<<endl; 00410 ctrlLocal = new PsMomeController((*ii).first, 00411 scenario, 00412 aKernelObjectFactory); 00413 } 00414 } 00415 else 00416 #endif 00417 if (option=="Mono") { 00418 cout<<"Simulation en version MonoProcessus réelle"<<endl; 00419 cout<<"Peut y avoir des problèmes si on utilise des entités sans calcul"<<endl; 00420 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00421 ctrlLocal = new PsMonoProcessController("MonoProc", 00422 scenario, 00423 aKernelObjectFactory); 00424 } 00425 else 00426 if (option=="Multi") { 00427 cout<<"Simulation en version MonoProcessus réelle, Multi-threader"<<endl; 00428 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00429 assert(argc>=4) ; 00430 ctrlLocal = new PsMultiThreadedController("MonoProc", 00431 scenario, 00432 aKernelObjectFactory, 00433 atoi(argv[3]) ); 00434 } 00435 else 00436 if (option=="MultiTimed") { 00437 cout<<"Simulation en version MonoProcessus réelle, Multi-threader"<<endl; 00438 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00439 assert(argc>=4) ; 00440 ctrlLocal = new PsnTimerControleur<PsMultiThreadedController>("MonoProc", 00441 scenario, 00442 aKernelObjectFactory, 00443 atoi(argv[3]) ); 00444 } 00445 00446 else { 00447 cout <<"Option non reconnue : _"<<option<<"_ simulation sans GUI"<<endl; 00448 aKernelObjectFactory= new PsKernelObjectClassicFactory(); 00449 ctrlLocal = new PsController("MonoProc", scenario, aKernelObjectFactory); 00450 } 00451 } 00452 00453 // Initialisation du display avec le choix operateur systeme ou argument 00454 ctrlLocal->NomDisplayX11(displayX11); 00455 try { 00456 ctest<<"Phase d'initialisation"<<endl; 00457 //sleep (30) ; 00458 ctrlLocal->init(); 00459 ctest<<"Phase de simulation"<<endl; 00460 00461 // demarrage de la simulation 00462 // boucle de simulation locale 00463 // controle des objets de simulation 00464 //un des objets de simulation va arreter l'execution 00465 ctrlLocal->run(); 00466 00467 ctest<<"Phase de terminaison"<<endl; 00468 delete ctrlLocal; 00469 } 00470 catch (PsException & e) { 00471 cerr<<typeid(e).name() <<" says : "<<endl; 00472 cerr<<e<<endl; 00473 } 00474 delete aKernelObjectFactory; 00475 if(t!= NULL) delete t; 00476 //L'affichage en commentaire montre que le compilateur ne voit pas le type concret de PsName::serveurDeNom, ce qu'il l'empêche d'appeller le bon operator delete, même si le bon destructeur est appelé. Limite de C++ ? 00477 //cout <<typeid(PsName::serveurDeNom).name()<<endl; 00478 delete PsName::serveurDeNom; 00479 exit(0); 00480 } // mainGlobal 00481
| Documentation generated on Mon Nov 25 15:24:59 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |