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