MAGiC  V5.0
Mailleurs Automatiques de Géometries intégrés à la Cao
ot_cpu.cpp
Aller à la documentation de ce fichier.
1 //####//------------------------------------------------------------
2 //####//------------------------------------------------------------
3 //####// MAGiC
4 //####// Jean Christophe Cuilliere et Vincent FRANCOIS
5 //####// Departement de Genie Mecanique - UQTR
6 //####//------------------------------------------------------------
7 //####// MAGIC est un projet de recherche de l equipe ERICCA
8 //####// du departement de genie mecanique de l Universite du Quebec a Trois Rivieres
9 //####// http://www.uqtr.ca/ericca
10 //####// http://www.uqtr.ca/
11 //####//------------------------------------------------------------
12 //####//------------------------------------------------------------
13 //####//
14 //####// ot_cpu.cpp
15 //####//
16 //####//------------------------------------------------------------
17 //####//------------------------------------------------------------
18 //####// COPYRIGHT 2000-2024
19 //####// jeu 13 jun 2024 11:54:00 EDT
20 //####//------------------------------------------------------------
21 //####//------------------------------------------------------------
22 #include "ot_cpu.h"
23 #include <stdio.h>
24 #include <map>
25 
28 
29 
30 
32 {
33  initialise();
34 }
35 
37 {
38  for (int i=0;i<mdd.tabcpu.size();i++)
39  tabcpu.insert(tabcpu.end(),mdd.tabcpu[i]);
40  for (int i=0;i<mdd.tabnom.size();i++)
41  tabnom.insert(tabnom.end(),mdd.tabnom[i]);
42 }
43 
45 {
46 }
47 
48 
50 {
51  tabcpu.clear();
52  tabnom.clear();
53  tabcpu.insert(tabcpu.end(),clock());
54  tabnom.insert(tabnom.end(),"Initialisation");
55 }
56 
57 
58 double OT_CPU::ajouter_etape(std::string nom)
59 {
60  tabcpu.insert(tabcpu.end(),clock());
61  tabnom.insert(tabnom.end(),nom);
62  double temps=tabcpu[tabcpu.size()-1]-tabcpu[tabcpu.size()-2];
63  return temps/CLOCKS_PER_SEC;
64 }
65 
67 {
68  return tabcpu.size()-1;
69 }
70 
71 void OT_CPU::get_etape(int num,std::string &nom,double &temps)
72 {
73  temps=1.*(tabcpu[num]-tabcpu[num-1]);
74  temps=temps*1./CLOCKS_PER_SEC;
75  nom=tabnom[num];
76 }
77 
78 
79 void OT_CPU::get_etape(std::string nom,double &temps)
80 {
81  temps=0.;
82  for (int i=0;i<get_nb_etape();i++)
83  {
84  std::string nomtmp;
85  double tempstmp;
86  get_etape(i+1,nomtmp,tempstmp);
87  if (nomtmp==nom) temps=temps+tempstmp;
88  }
89 
90 }
91 
92 void OT_CPU::get_etape(int num1,int num2,std::string &nom,double &temps)
93 {
94  temps=1.*(tabcpu[num2]-tabcpu[num1-1]);
95  temps=temps*1/CLOCKS_PER_SEC;
96  nom=tabnom[num1]+"-"+tabnom[num2];
97 }
98 
99 void OT_CPU::get_total(int num,double &temps)
100 {
101  temps=1.*(tabcpu[num]-tabcpu[0]);
102  temps=temps*1./CLOCKS_PER_SEC;
103 }
104 
105 
106 
107 void OT_CPU::get_tabfinal(std::vector<std::string> &tab)
108 {
109  tab.clear();
110  std::string nom;
111  double temps;
112  char mess[255];
113  for (int i=0;i<get_nb_etape();i++)
114  {
115  get_etape(i+1,nom,temps);
116  char mess[255];
117  sprintf(mess," %30s : %.2lf s",nom.c_str(),temps);
118  tab.insert(tab.end(),mess);
119  }
120  get_total(get_nb_etape(),temps);
121  nom="Total";
122  sprintf(mess," %30s : %.2lf s",nom.c_str(),temps);
123  tab.insert(tab.end(),mess);
124 }
125 
126 void OT_CPU::get_tabfinalcompresse(std::vector<std::string> &tab)
127 {
128  tab.clear();
129  std::string nom;
130  double temps;
131  char mess[255];
132  std::map<std::string,std::string> lst;
133  for (int i=0;i<get_nb_etape();i++)
134  {
135  get_etape(i+1,nom,temps);
136  std::map<std::string,std::string>::iterator it=lst.find(nom);
137  if (it==lst.end())
138  {
139  get_etape(nom,temps);
140  char mess[255];
141  sprintf(mess," %30s : %.2lf s",nom.c_str(),temps);
142  tab.insert(tab.end(),mess);
143  std::pair<std::string,std::string> tmp(nom,nom);
144  lst.insert(tmp);
145  }
146  }
147  get_total(get_nb_etape(),temps);
148  nom="Total";
149  sprintf(mess," %30s : %.2lf s",nom.c_str(),temps);
150  tab.insert(tab.end(),mess);
151 }
152 
153 
154 
155 void OT_CPU::enregistrer(char* fichier)
156 {
157  std::vector<std::string> tab1,tab2;
158  get_tabfinal(tab1);
159  get_tabfinalcompresse(tab2);
160  FILE *out=fopen(fichier,"wt");
161  for (int i=0;i<tab1.size();i++)
162  fprintf(out,"%s\n",(char*)tab1[i].c_str());
163  for (int i=0;i<tab2.size();i++)
164  fprintf(out,"%s\n",(char*)tab2[i].c_str());
165  fclose(out);
166 }
167 
168 void OT_CPU::affiche(void)
169 {
170  std::vector<std::string> tab1;
171  get_tabfinal(tab1);
172  for (int i=0;i<tab1.size();i++)
173  printf("%s\n",(char*)tab1[i].c_str());
174 
175 }
176 
178 {
179  std::vector<std::string> tab2;
180  get_tabfinalcompresse(tab2);
181  for (int i=0;i<tab2.size();i++)
182  printf("%s\n",(char*)tab2[i].c_str());
183 }
184 
CODE_ASTER_CPU
double CODE_ASTER_CPU
Definition: ot_cpu.cpp:26
OT_CPU::tabcpu
std::vector< clock_t > tabcpu
Definition: ot_cpu.h:54
OT_CPU::get_nb_etape
int get_nb_etape(void)
Definition: ot_cpu.cpp:66
OT_CPU
Definition: ot_cpu.h:31
OT_CPU::OT_CPU
OT_CPU()
Definition: ot_cpu.cpp:31
ot_cpu.h
OT_CPU::ajouter_etape
double ajouter_etape(std::string nom)
Definition: ot_cpu.cpp:58
OT_CPU::initialise
void initialise(void)
Definition: ot_cpu.cpp:49
OT_CPU::affichecompresser
void affichecompresser(void)
Definition: ot_cpu.cpp:177
OT_CPU::affiche
void affiche(void)
Definition: ot_cpu.cpp:168
OT_CPU::get_tabfinal
void get_tabfinal(std::vector< std::string > &tab)
Definition: ot_cpu.cpp:107
OT_CPU::get_total
void get_total(int num, double &temps)
Definition: ot_cpu.cpp:99
OT_CPU::get_etape
void get_etape(int num, std::string &nom, double &temps)
Definition: ot_cpu.cpp:71
OT_CPU::tabnom
std::vector< std::string > tabnom
Definition: ot_cpu.h:55
OT_CPU::get_tabfinalcompresse
void get_tabfinalcompresse(std::vector< std::string > &tab)
Definition: ot_cpu.cpp:126
CODE_ASTER_ECOULE
double CODE_ASTER_ECOULE
Definition: ot_cpu.cpp:27
OT_CPU::enregistrer
void enregistrer(char *fichier)
Definition: ot_cpu.cpp:155
OT_CPU::~OT_CPU
~OT_CPU()
Definition: ot_cpu.cpp:44