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 |
|
|
printf("***********************************************"); |
10 |
|
|
printf("parra.exe nom_lanceur nb_cpu nb_echantillon (nom_fichier_parametre pour polycristaux)\n"); |
11 |
|
|
printf("***********************************************"); |
12 |
|
|
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 |
|
|
if(type_microstructure==TYPE_MICROSTRUCTURE::POLYCRISTAUX) |
39 |
|
|
{ |
40 |
|
|
param.lire((char*)parametre.c_str()); |
41 |
|
|
nomcumul=param.get_nom("fichiercumul"); |
42 |
|
|
nomcumul1 = nomcumul+".txt"; |
43 |
|
|
nomcumul2 = nomcumul+".gnu"; |
44 |
|
|
} |
45 |
francois |
1028 |
|
46 |
|
|
printf("\033[1;4;32;41m***********************************************\033[0m\n"); |
47 |
|
|
printf("\033[1;4;32;41m******* Lanceur parralléle de code ***********\033[0m\n"); |
48 |
|
|
printf("\033[1;4;32;41m***********************************************\033[0m\n"); |
49 |
couturad |
1030 |
fflush(stdout); |
50 |
francois |
1028 |
int nbthreads, tid; |
51 |
|
|
omp_set_num_threads(nbcpu); |
52 |
|
|
#pragma omp parallel private ( tid ) shared ( nbthreads ) |
53 |
|
|
{ |
54 |
|
|
tid = omp_get_thread_num(); |
55 |
|
|
//if( 0 == tid ) |
56 |
|
|
#pragma omp single |
57 |
|
|
nbthreads = omp_get_num_threads(); |
58 |
|
|
char commande[255]; |
59 |
couturad |
1029 |
sprintf(commande,"mkdir -p cpu%d",tid); |
60 |
francois |
1028 |
system(commande); |
61 |
couturad |
1029 |
if(type_microstructure==TYPE_MICROSTRUCTURE::POLYCRISTAUX) |
62 |
|
|
{ |
63 |
francois |
1028 |
sprintf(commande,"cp vasy vasy_par param_aster.txt %s %s2 ./cpu%d",parametre.c_str(),parametre.c_str(),tid); |
64 |
|
|
system(commande); |
65 |
couturad |
1029 |
} |
66 |
|
|
|
67 |
francois |
1028 |
//printf("Hello World! I am thread %d/%d\ n", tid, nbthreads); |
68 |
|
|
#pragma omp for schedule(dynamic) |
69 |
|
|
for (int i=0;i<nbechan;i++) |
70 |
|
|
// printf("Bonjour %d à vous Je suis le calcul %d %d\n",i,tid,nbthreads); |
71 |
|
|
{ |
72 |
couturad |
1029 |
printf("\033[1;4;32;41mCPU numero %d. Calcul numero %d de %d\033[0m\n",tid,i+1,nbechan); |
73 |
couturad |
1030 |
fflush(stdout); |
74 |
couturad |
1029 |
if(type_microstructure==TYPE_MICROSTRUCTURE::POLYCRISTAUX) |
75 |
|
|
{ |
76 |
|
|
sprintf(commande,"cd cpu%d;%s",tid,executable.c_str()); |
77 |
|
|
system(commande); |
78 |
|
|
} |
79 |
|
|
else if(type_microstructure==TYPE_MICROSTRUCTURE::PARTICULES) |
80 |
|
|
{ |
81 |
|
|
sprintf(commande,"mkdir -p cpu%d/e%d; cd cpu%d/e%d;%s",tid,i,tid,i,executable.c_str()); |
82 |
|
|
system(commande); |
83 |
|
|
} |
84 |
|
|
|
85 |
francois |
1028 |
} |
86 |
|
|
} |
87 |
couturad |
1029 |
if(type_microstructure==TYPE_MICROSTRUCTURE::POLYCRISTAUX) |
88 |
|
|
{ |
89 |
francois |
1028 |
printf("\n\033[1;4;32;41m***** Rassemblement des résultats *************\033[0m\n\n\n"); |
90 |
couturad |
1030 |
fflush(stdout); |
91 |
francois |
1028 |
char commande[2550]; |
92 |
|
|
char commande2[2550]; |
93 |
|
|
sprintf(commande,"tail -n+1 ./cpu0/%s;",nomcumul1.c_str()); |
94 |
|
|
for (int i=1;i<nbthreads;i++) |
95 |
|
|
sprintf(commande,"%stail -n+2 ./cpu%d/%s; ",commande,i,nomcumul1.c_str()); |
96 |
|
|
sprintf(commande2,"(%s)>%s",commande,nomcumul1.c_str()); |
97 |
|
|
system(commande2); |
98 |
|
|
sprintf(commande,"tail -n+1 ./cpu0/%s>%s",nomcumul2.c_str(),nomcumul2.c_str()); |
99 |
|
|
system(commande); |
100 |
couturad |
1029 |
} |
101 |
francois |
1028 |
|
102 |
|
|
|
103 |
|
|
printf("\033[1;4;32;41m***********************************************\033[0m\n"); |
104 |
|
|
printf("\033[1;4;32;41m********************* Fin ********************\033[0m\n"); |
105 |
|
|
printf("\033[1;4;32;41m***********************************************\033[0m\n"); |
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
return EXIT_SUCCESS; |
110 |
couturad |
1029 |
} |