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 |
|
|
std::string parametre=argv[4]; |
11 |
|
|
|
12 |
|
|
OT_PARAMETRES param; |
13 |
|
|
param.lire((char*)parametre.c_str()); |
14 |
|
|
std::string nomcumul=param.get_nom("fichiercumul"); |
15 |
|
|
std::string nomcumul1 = nomcumul+".txt"; |
16 |
|
|
std::string nomcumul2 = nomcumul+".gnu"; |
17 |
|
|
|
18 |
|
|
|
19 |
|
|
printf("\033[1;4;32;41m***********************************************\033[0m\n"); |
20 |
|
|
printf("\033[1;4;32;41m******* Lanceur parralléle de code ***********\033[0m\n"); |
21 |
|
|
printf("\033[1;4;32;41m***********************************************\033[0m\n"); |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
int nbthreads, tid; |
27 |
|
|
omp_set_num_threads(nbcpu); |
28 |
|
|
#pragma omp parallel private ( tid ) shared ( nbthreads ) |
29 |
|
|
{ |
30 |
|
|
tid = omp_get_thread_num(); |
31 |
|
|
//if( 0 == tid ) |
32 |
|
|
#pragma omp single |
33 |
|
|
nbthreads = omp_get_num_threads(); |
34 |
|
|
char commande[255]; |
35 |
|
|
sprintf(commande,"mkdir cpu%d",tid); |
36 |
|
|
system(commande); |
37 |
|
|
sprintf(commande,"cp vasy vasy_par param_aster.txt %s %s2 ./cpu%d",parametre.c_str(),parametre.c_str(),tid); |
38 |
|
|
system(commande); |
39 |
|
|
//printf("Hello World! I am thread %d/%d\ n", tid, nbthreads); |
40 |
|
|
#pragma omp for schedule(dynamic) |
41 |
|
|
for (int i=0;i<nbechan;i++) |
42 |
|
|
// printf("Bonjour %d à vous Je suis le calcul %d %d\n",i,tid,nbthreads); |
43 |
|
|
{ |
44 |
|
|
printf("\033[1;4;32;41mCPU numero %d. Calcul numero %d de %d\033[0m\n",tid,i+1,nbechan); |
45 |
|
|
sprintf(commande,"cd cpu%d;%s",tid,executable.c_str()); |
46 |
|
|
system(commande); |
47 |
|
|
} |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
printf("\n\033[1;4;32;41m***** Rassemblement des résultats *************\033[0m\n\n\n"); |
51 |
|
|
char commande[2550]; |
52 |
|
|
char commande2[2550]; |
53 |
|
|
sprintf(commande,"tail -n+1 ./cpu0/%s;",nomcumul1.c_str()); |
54 |
|
|
for (int i=1;i<nbthreads;i++) |
55 |
|
|
sprintf(commande,"%stail -n+2 ./cpu%d/%s; ",commande,i,nomcumul1.c_str()); |
56 |
|
|
sprintf(commande2,"(%s)>%s",commande,nomcumul1.c_str()); |
57 |
|
|
system(commande2); |
58 |
|
|
sprintf(commande,"tail -n+1 ./cpu0/%s>%s",nomcumul2.c_str(),nomcumul2.c_str()); |
59 |
|
|
system(commande); |
60 |
|
|
|
61 |
|
|
|
62 |
|
|
printf("\033[1;4;32;41m***********************************************\033[0m\n"); |
63 |
|
|
printf("\033[1;4;32;41m********************* Fin ********************\033[0m\n"); |
64 |
|
|
printf("\033[1;4;32;41m***********************************************\033[0m\n"); |
65 |
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
return EXIT_SUCCESS; |
69 |
|
|
} |