ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/app/microstructure/src/lanceurparra.cpp
Revision: 1071
Committed: Thu Jul 8 20:15:44 2021 UTC (4 years, 1 month ago) by francois
File size: 3782 byte(s)
Log Message:
centralisation automatique resultat pour les polycristaux en parralelle ou non

File Contents

# Content
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string>
4 #include <omp.h>
5 #include "ot_parametres.h"
6 int main(int argc,char **argv) {
7 if(argc < 4)
8 {
9 printf("***********************************************\n");
10 printf("parra.exe nom_lanceur nb_cpu nb_echantillon (nom_fichier_parametre pour polycristaux)\n");
11 printf("***********************************************\n");
12 return 0;
13
14 }
15
16 std::string executable=argv[1];
17 int nbcpu=atoi(argv[2]);
18 int nbechan=atoi(argv[3]);
19
20
21 std::string parametre;
22 if(argc==5) parametre=argv[4];
23
24
25 enum TYPE_MICROSTRUCTURE{POLYCRISTAUX=0,
26 PARTICULES=1};
27 int type_microstructure=TYPE_MICROSTRUCTURE::POLYCRISTAUX;
28 if(argc<5)
29 {
30 type_microstructure=TYPE_MICROSTRUCTURE::PARTICULES;
31 executable="../../"+executable;
32 }
33
34 OT_PARAMETRES param;
35 std::string nomcumul;
36 std::string nomcumul1;
37 std::string nomcumul2;
38 std::string nomaster;
39 if(type_microstructure==TYPE_MICROSTRUCTURE::POLYCRISTAUX)
40 {
41 param.lire((char*)parametre.c_str());
42 nomcumul=param.get_nom("fichiercumul");
43 nomaster=param.get_nom("paramaster");
44 nomcumul1 = nomcumul+".txt";
45 nomcumul2 = nomcumul+".gnu";
46 }
47
48 printf("\033[1;4;32;41m***********************************************\033[0m\n");
49 printf("\033[1;4;32;41m******* Lanceur parralléle de code ***********\033[0m\n");
50 printf("\033[1;4;32;41m***********************************************\033[0m\n");
51 fflush(stdout);
52 int nbthreads, tid;
53 omp_set_num_threads(nbcpu);
54 #pragma omp parallel private ( tid ) shared ( nbthreads )
55 {
56 tid = omp_get_thread_num();
57 //if( 0 == tid )
58 #pragma omp single
59 nbthreads = omp_get_num_threads();
60 char commande[255];
61 sprintf(commande,"mkdir -p cpu%d",tid);
62 system(commande);
63 if(type_microstructure==TYPE_MICROSTRUCTURE::POLYCRISTAUX)
64 {
65 sprintf(commande,"cp vasy vasy_par %s %s %s2 ./cpu%d",nomaster.c_str(),parametre.c_str(),parametre.c_str(),tid);
66 system(commande);
67 sprintf(commande,"./cpu%d/%s",tid,parametre.c_str());
68 OT_PARAMETRES paramcpu;
69 paramcpu.lire(commande);
70 std::string nomcumulcpu=paramcpu.get_nom("fichiercumul");
71 nomcumulcpu="../"+nomcumulcpu;
72 paramcpu.change_valeur("fichiercumul",nomcumulcpu);
73 paramcpu.enregistrer(commande);
74 }
75
76 //printf("Hello World! I am thread %d/%d\ n", tid, nbthreads);
77 #pragma omp for schedule(dynamic)
78 for (int i=0;i<nbechan;i++)
79 // printf("Bonjour %d à vous Je suis le calcul %d %d\n",i,tid,nbthreads);
80 {
81 printf("\033[1;4;32;41mCPU numero %d. Calcul numero %d de %d\033[0m\n",tid,i+1,nbechan);
82 fflush(stdout);
83 if(type_microstructure==TYPE_MICROSTRUCTURE::POLYCRISTAUX)
84 {
85 sprintf(commande,"cd cpu%d;%s",tid,executable.c_str());
86 system(commande);
87 }
88 else if(type_microstructure==TYPE_MICROSTRUCTURE::PARTICULES)
89 {
90 sprintf(commande,"mkdir -p cpu%d/e%d; cd cpu%d/e%d;%s",tid,i,tid,i,executable.c_str());
91 system(commande);
92 }
93
94 }
95 }
96 /*if(type_microstructure==TYPE_MICROSTRUCTURE::POLYCRISTAUX)
97 {
98 printf("\n\033[1;4;32;41m***** Rassemblement des résultats *************\033[0m\n\n\n");
99 fflush(stdout);
100 char commande[2550];
101 char commande2[2550];
102 sprintf(commande,"tail -n+1 ./cpu0/%s;",nomcumul1.c_str());
103 for (int i=1;i<nbthreads;i++)
104 sprintf(commande,"%stail -n+2 ./cpu%d/%s; ",commande,i,nomcumul1.c_str());
105 sprintf(commande2,"(%s)>%s",commande,nomcumul1.c_str());
106 system(commande2);
107 sprintf(commande,"tail -n+1 ./cpu0/%s>%s",nomcumul2.c_str(),nomcumul2.c_str());
108 system(commande);
109 }*/
110
111
112 printf("\033[1;4;32;41m***********************************************\033[0m\n");
113 printf("\033[1;4;32;41m********************* Fin ********************\033[0m\n");
114 printf("\033[1;4;32;41m***********************************************\033[0m\n");
115
116
117
118 return EXIT_SUCCESS;
119 }