1 |
francois |
1028 |
#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 |
francois |
1045 |
if(argc < 4) |
8 |
|
|
{ |
9 |
francois |
1071 |
printf("***********************************************\n"); |
10 |
francois |
1045 |
printf("parra.exe nom_lanceur nb_cpu nb_echantillon (nom_fichier_parametre pour polycristaux)\n"); |
11 |
francois |
1071 |
printf("***********************************************\n"); |
12 |
francois |
1045 |
return 0; |
13 |
|
|
|
14 |
|
|
} |
15 |
|
|
|
16 |
francois |
1028 |
std::string executable=argv[1]; |
17 |
|
|
int nbcpu=atoi(argv[2]); |
18 |
|
|
int nbechan=atoi(argv[3]); |
19 |
|
|
|
20 |
couturad |
1029 |
|
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 |
francois |
1028 |
OT_PARAMETRES param; |
35 |
couturad |
1029 |
std::string nomcumul; |
36 |
|
|
std::string nomcumul1; |
37 |
|
|
std::string nomcumul2; |
38 |
francois |
1071 |
std::string nomaster; |
39 |
couturad |
1029 |
if(type_microstructure==TYPE_MICROSTRUCTURE::POLYCRISTAUX) |
40 |
|
|
{ |
41 |
|
|
param.lire((char*)parametre.c_str()); |
42 |
|
|
nomcumul=param.get_nom("fichiercumul"); |
43 |
francois |
1071 |
nomaster=param.get_nom("paramaster"); |
44 |
couturad |
1029 |
nomcumul1 = nomcumul+".txt"; |
45 |
|
|
nomcumul2 = nomcumul+".gnu"; |
46 |
|
|
} |
47 |
francois |
1028 |
|
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 |
couturad |
1030 |
fflush(stdout); |
52 |
francois |
1028 |
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 |
couturad |
1029 |
sprintf(commande,"mkdir -p cpu%d",tid); |
62 |
francois |
1028 |
system(commande); |
63 |
couturad |
1029 |
if(type_microstructure==TYPE_MICROSTRUCTURE::POLYCRISTAUX) |
64 |
|
|
{ |
65 |
francois |
1071 |
sprintf(commande,"cp vasy vasy_par %s %s %s2 ./cpu%d",nomaster.c_str(),parametre.c_str(),parametre.c_str(),tid); |
66 |
francois |
1028 |
system(commande); |
67 |
francois |
1071 |
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 |
couturad |
1029 |
} |
75 |
|
|
|
76 |
francois |
1028 |
//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 |
couturad |
1029 |
printf("\033[1;4;32;41mCPU numero %d. Calcul numero %d de %d\033[0m\n",tid,i+1,nbechan); |
82 |
couturad |
1030 |
fflush(stdout); |
83 |
couturad |
1029 |
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 |
francois |
1028 |
} |
95 |
|
|
} |
96 |
francois |
1071 |
/*if(type_microstructure==TYPE_MICROSTRUCTURE::POLYCRISTAUX) |
97 |
couturad |
1029 |
{ |
98 |
francois |
1028 |
printf("\n\033[1;4;32;41m***** Rassemblement des résultats *************\033[0m\n\n\n"); |
99 |
couturad |
1030 |
fflush(stdout); |
100 |
francois |
1028 |
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 |
francois |
1071 |
}*/ |
110 |
francois |
1028 |
|
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 |
couturad |
1029 |
} |