terminate called after throwing an instance of 'std::bad_alloc'
Bonjour à tous,
Etant débutant en C++, je me retrouve bloqué face à ce problème: lorsque j'exécute mon programme avec un nombre élevé d'itérations (60 000, j'exécute en boucle un programme!), j'ai le message suivant:
terminate called after throwing an instance of 'std::bad_alloc'
Je pense que c'est dû à ma mauvaise conception de mon programme qui est le suivant:
premier fichier: parametric.cc
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <ostream>
#include "vnode.h"
#include "Inputs.h"
using namespace std;
using namespace vnodelp;
template<typename var_type>
void parametric(int n,var_type*yp,const var_type*y,var_type t,void*param)
/*
Parameters:
n : size of
*/
{
Inputs*p = (Inputs*)param;
interval a = p->a;
interval b = p->b;
interval c = p->c;
yp[0] = a*(y[1]-y[0]);
yp[1] = y[0]*(b-y[2])-y[1];
yp[2] = y[0]*y[1]-c*y[2];
}
//iVector fct(interval param1, interval param2, interval param3, interval tend)
iVector myProblem(Inputs input, interval tend)
/*
mon programme
Parameters:
p pointer to parameter struture Input
tend: pointer to final time interval for ^precision
*/
{
const int n = 3; // for security reasons
interval t = 0.0; // initial time t
iVector y(n); // vnode type.
y[0] = 15.0;
y[1] = 15.0;
y[2] = 36.0;
/*
Inputs table;
Inputs *p=(Inputs*)pInput;
table.a = p->a;
table.b = p->b;
table.c = p->c;
*/
/*
Inputs table;
table.a = param1;
table.b = param2;
table.c = param3;
*/
AD*ad = new FADBAD_AD(n,parametric,parametric,&input);
VNODE*Solver = new VNODE(ad);
Solver->integrate(t,y,tend);
if(!Solver->successful())
cout<<"VNODE-LP could not reach t = "<<tend<<endl;
delete Solver;
delete ad;
//delete &n;
//delete &t;
return y;
} |
deuxième fichier: parametric.h
Code:
1 2 3 4 5 6 7 8 9 10 11
| #ifndef parametric
#define parametric
#include "vnode.h"
#include "Inputs.h"
iVector myProblem(Inputs input, interval tend);
//iVector fct(interval param1, interval param2, interval param3, interval tend);
#endif |
troisième fichier: executable.cc (qui contient mon main)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #include <ostream>
#include "parametric.h"
#include "vnode.h"
#include <time.h>
int main() {
int nbexecutions = 60000;
interval tend = interval(0.001);
Inputs parameterTable;
parameterTable.a=interval(11,15);
parameterTable.b=interval(11,12);
parameterTable.c=interval(29,35);
iVector i;
int j;
time_t debut, fin;
double duree;
debut=time(NULL);
for (j=1; j<=nbexecutions; j++){
i = myProblem(parameterTable,tend);
}
fin=time(NULL);
duree=difftime(fin, debut);
printVector(i);
cout<<"program duration : "<<duree<<endl;
return 0;
} |
toute aide sera la bienvenu :ccool:!