Please...help....
Alexandre
-
teebo Messages postés 33570 Date d'inscription Statut Modérateur Dernière intervention -
teebo Messages postés 33570 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour,
Suite a la demande de jisisv voici un extrait de mon code.
J'aimerais savoir si dans cet extrait de code et surtout dans la
procedure dispersion, il y a une erreur d'utilisation de la memoire
car lorsque que je lance mon programme, il apparait quelque fois le
message segmentation fault!
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define ran() (float) rand()/RAND_MAX
/*Definition d'une structure qui contient les proprietes
necessaires au modele*/
typedef struct toto {
float Q_TRUNC;
float SIG_ALPHA;
float SIG_BETA;
float H_CENTER;
float SIG_HK;
float SIG_HI;
float kx;
float norm;
float RATIO;
float MSAT;
float ANISOTROPIE;
int tdim;
int npom;
float *hi_tab;
float *hk_tab;
float *ptab;
float *alpha;
float *beta;
float *ux;
float *uy;
float *uz;
char *etat;
} sw_model;
/*Allocation de la memoire dynamique necessaire aux tableaux de
vecteurs orientant les operateurs de SW*/
int create_model( sw_model *pmodel )
{
int tmax;
tmax= pmodel->npom;
pmodel->hi_tab = ( float* ) calloc( tmax, sizeof(float));
pmodel->hk_tab = ( float* ) calloc( tmax, sizeof(float));
pmodel->ptab = ( float* ) calloc( tmax, sizeof(float));
pmodel->alpha = (float*) calloc( tmax, sizeof(float));
pmodel->beta = (float*) calloc( tmax, sizeof(float));
pmodel->ux = (float*) calloc( tmax, sizeof(float));
pmodel->uy = (float*) calloc( tmax, sizeof(float));
pmodel->uz = (float*) calloc( tmax, sizeof(float));
pmodel->etat = (char*) calloc( tmax, sizeof(char));
return(1);
}
/*routine de choix aleatoire de valeur*/
double ran_gauss()
{
double r=0.0;
int i;
for( i=0; i<=100; i++ )
r += ( double ) rand()/RAND_MAX - 0.5;
return( r/2.9 );
}
/*routines de changement de repere*/
void trans_o3x( float x, float y, float z,
float *xt, float *yt, float *zt, float a )
{
*xt= x;
*yt= cos(a)*y - sin(a)*z;
*zt= sin(a)*y + cos(a)*z;
}
void trans_o3y( float x, float y, float z,
float *xt, float *yt, float *zt, float a )
{
*yt= y;
*xt= cos(a)*x - sin(a)*z;
*zt= sin(a)*x + cos(a)*z;
}
/*Procedure de repartition aleatoire des vecteurs "axe facile" des operateurs de
Stoner-Wohlfarth et des couples (hi,hc) des points du plan de Preisach: la routine
qui me pose probleme: segmentation fault pour npom~800*/
void dispersion( sw_model *pmodel )
{
int i,nb_ope;
FILE *dat1, *dat2;
float x,y,z,x0,y0,z0;
float a, b, beta, alpha, norm;
nb_ope=pmodel->npom;
printf("nbre d'operateurs:%d\n",nb_ope);
dat1=
fopen("/home/perso/fbernard/alex_volatier/Essais/verifications/resultat/nouveau1.dat","wb");
if ( dat1==0)
{
printf("echec ouverture de disb.dat\n");
exit (1);
}
printf("Creation d'une distribution spatiale...\n");
/*sorte de reinitialisation du generateur de nombre aleatoire*/
srand( (unsigned)time( NULL ) );
for( i=0; i <pmodel->npom;i++)
{
alpha= pmodel->SIG_ALPHA*ran_gauss()*3.1415/180;
beta= pmodel->SIG_BETA*ran_gauss()*3.1415/180;
x0= cos(beta);
z0= sin(beta);
y0=0.0 ;
/*engendrer la rotation autour de x*/
trans_o3x( x0, y0, z0, &x, &y, &z, alpha );
/* Creer Anisotropie */
trans_o3y( x, y, z, &pmodel->ux[i], &pmodel->uy[i],&pmodel->uz[i],
pmodel->ANISOTROPIE );
pmodel->alpha[i]=alpha ;
pmodel->beta[i] =beta ;
fprintf( dat1, "%d %f %f %f \n",i,pmodel->ux[i], pmodel->uy[i], pmodel->uz[i]);
fflush(dat1);
/*printf( "ligne:%d,ux:%f uy:%f uz:%f\n",i,pmodel->ux[i],pmodel->uy[i],
pmodel->uz[i]);*/
}
printf("...done\n\n");
fclose( dat1 );
/* distribution de Preisach*/
dat2=
fopen("/home/perso/fbernard/alex_volatier/Essais/verifications/resultat/nouveau2.dat","wb");
if ( dat2==0)
{
printf("echec ouverture de pdisb.dat\n");
exit (1);
}
printf("Creation de la distribution de Preisach...\n");
srand( (unsigned)time( NULL ) );
for( i=0; i<pmodel->npom; i++ )
{
do
{
pmodel->hi_tab[i]= 3*pmodel->SIG_HI*( 2*ran()-1 );
printf("Creation de hi:%f...\n",pmodel->hi_tab[i]);
pmodel->hk_tab[i]= 3*pmodel->SIG_HK*( 2*ran()-1)+pmodel->H_CENTER;
printf("Creation de hk:%f...\n",pmodel->hk_tab[i]);
pmodel->ptab[i]=pr_dens( pmodel->H_CENTER, pmodel->SIG_HI,pmodel->SIG_HK,
pmodel->hi_tab[i], pmodel->hk_tab[i] );
printf("Calcul de pdens:%f...\n\n",pmodel->ptab[i]);
printf("Calcul de limite:%f...\n\n",exp(-9/2));
}
while( pmodel->ptab[i] < exp(-3*3/2 ));
printf("couple %d OK!!\n",i);
fflush(dat2);
printf("couple %d OK!!\n",i+1);
fflush(dat2);
/*segmentation ici quelque fois!!*/
fprintf( dat2, "%f %f \n", pmodel->hi_tab[i], pmodel->hk_tab[i] );
fflush(dat2);
printf("couple %d OK!!\n",i+2);
pmodel->hk_tab[i] *= pmodel->RATIO;
}
printf("...done\n\n");
fclose( dat2 );
}
void liberation(sw_model *pmodel)
{
free(pmodel->hi_tab);
free(pmodel->hk_tab );
free(pmodel->ptab );
free(pmodel->alpha );
free(pmodel->beta );
free(pmodel->ux );
free(pmodel->uy );
free(pmodel->uz );
free(pmodel->etat );
}
Merci d'avance aux ames charitables et surtout patientes!
Alexandre
Suite a la demande de jisisv voici un extrait de mon code.
J'aimerais savoir si dans cet extrait de code et surtout dans la
procedure dispersion, il y a une erreur d'utilisation de la memoire
car lorsque que je lance mon programme, il apparait quelque fois le
message segmentation fault!
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define ran() (float) rand()/RAND_MAX
/*Definition d'une structure qui contient les proprietes
necessaires au modele*/
typedef struct toto {
float Q_TRUNC;
float SIG_ALPHA;
float SIG_BETA;
float H_CENTER;
float SIG_HK;
float SIG_HI;
float kx;
float norm;
float RATIO;
float MSAT;
float ANISOTROPIE;
int tdim;
int npom;
float *hi_tab;
float *hk_tab;
float *ptab;
float *alpha;
float *beta;
float *ux;
float *uy;
float *uz;
char *etat;
} sw_model;
/*Allocation de la memoire dynamique necessaire aux tableaux de
vecteurs orientant les operateurs de SW*/
int create_model( sw_model *pmodel )
{
int tmax;
tmax= pmodel->npom;
pmodel->hi_tab = ( float* ) calloc( tmax, sizeof(float));
pmodel->hk_tab = ( float* ) calloc( tmax, sizeof(float));
pmodel->ptab = ( float* ) calloc( tmax, sizeof(float));
pmodel->alpha = (float*) calloc( tmax, sizeof(float));
pmodel->beta = (float*) calloc( tmax, sizeof(float));
pmodel->ux = (float*) calloc( tmax, sizeof(float));
pmodel->uy = (float*) calloc( tmax, sizeof(float));
pmodel->uz = (float*) calloc( tmax, sizeof(float));
pmodel->etat = (char*) calloc( tmax, sizeof(char));
return(1);
}
/*routine de choix aleatoire de valeur*/
double ran_gauss()
{
double r=0.0;
int i;
for( i=0; i<=100; i++ )
r += ( double ) rand()/RAND_MAX - 0.5;
return( r/2.9 );
}
/*routines de changement de repere*/
void trans_o3x( float x, float y, float z,
float *xt, float *yt, float *zt, float a )
{
*xt= x;
*yt= cos(a)*y - sin(a)*z;
*zt= sin(a)*y + cos(a)*z;
}
void trans_o3y( float x, float y, float z,
float *xt, float *yt, float *zt, float a )
{
*yt= y;
*xt= cos(a)*x - sin(a)*z;
*zt= sin(a)*x + cos(a)*z;
}
/*Procedure de repartition aleatoire des vecteurs "axe facile" des operateurs de
Stoner-Wohlfarth et des couples (hi,hc) des points du plan de Preisach: la routine
qui me pose probleme: segmentation fault pour npom~800*/
void dispersion( sw_model *pmodel )
{
int i,nb_ope;
FILE *dat1, *dat2;
float x,y,z,x0,y0,z0;
float a, b, beta, alpha, norm;
nb_ope=pmodel->npom;
printf("nbre d'operateurs:%d\n",nb_ope);
dat1=
fopen("/home/perso/fbernard/alex_volatier/Essais/verifications/resultat/nouveau1.dat","wb");
if ( dat1==0)
{
printf("echec ouverture de disb.dat\n");
exit (1);
}
printf("Creation d'une distribution spatiale...\n");
/*sorte de reinitialisation du generateur de nombre aleatoire*/
srand( (unsigned)time( NULL ) );
for( i=0; i <pmodel->npom;i++)
{
alpha= pmodel->SIG_ALPHA*ran_gauss()*3.1415/180;
beta= pmodel->SIG_BETA*ran_gauss()*3.1415/180;
x0= cos(beta);
z0= sin(beta);
y0=0.0 ;
/*engendrer la rotation autour de x*/
trans_o3x( x0, y0, z0, &x, &y, &z, alpha );
/* Creer Anisotropie */
trans_o3y( x, y, z, &pmodel->ux[i], &pmodel->uy[i],&pmodel->uz[i],
pmodel->ANISOTROPIE );
pmodel->alpha[i]=alpha ;
pmodel->beta[i] =beta ;
fprintf( dat1, "%d %f %f %f \n",i,pmodel->ux[i], pmodel->uy[i], pmodel->uz[i]);
fflush(dat1);
/*printf( "ligne:%d,ux:%f uy:%f uz:%f\n",i,pmodel->ux[i],pmodel->uy[i],
pmodel->uz[i]);*/
}
printf("...done\n\n");
fclose( dat1 );
/* distribution de Preisach*/
dat2=
fopen("/home/perso/fbernard/alex_volatier/Essais/verifications/resultat/nouveau2.dat","wb");
if ( dat2==0)
{
printf("echec ouverture de pdisb.dat\n");
exit (1);
}
printf("Creation de la distribution de Preisach...\n");
srand( (unsigned)time( NULL ) );
for( i=0; i<pmodel->npom; i++ )
{
do
{
pmodel->hi_tab[i]= 3*pmodel->SIG_HI*( 2*ran()-1 );
printf("Creation de hi:%f...\n",pmodel->hi_tab[i]);
pmodel->hk_tab[i]= 3*pmodel->SIG_HK*( 2*ran()-1)+pmodel->H_CENTER;
printf("Creation de hk:%f...\n",pmodel->hk_tab[i]);
pmodel->ptab[i]=pr_dens( pmodel->H_CENTER, pmodel->SIG_HI,pmodel->SIG_HK,
pmodel->hi_tab[i], pmodel->hk_tab[i] );
printf("Calcul de pdens:%f...\n\n",pmodel->ptab[i]);
printf("Calcul de limite:%f...\n\n",exp(-9/2));
}
while( pmodel->ptab[i] < exp(-3*3/2 ));
printf("couple %d OK!!\n",i);
fflush(dat2);
printf("couple %d OK!!\n",i+1);
fflush(dat2);
/*segmentation ici quelque fois!!*/
fprintf( dat2, "%f %f \n", pmodel->hi_tab[i], pmodel->hk_tab[i] );
fflush(dat2);
printf("couple %d OK!!\n",i+2);
pmodel->hk_tab[i] *= pmodel->RATIO;
}
printf("...done\n\n");
fclose( dat2 );
}
void liberation(sw_model *pmodel)
{
free(pmodel->hi_tab);
free(pmodel->hk_tab );
free(pmodel->ptab );
free(pmodel->alpha );
free(pmodel->beta );
free(pmodel->ux );
free(pmodel->uy );
free(pmodel->uz );
free(pmodel->etat );
}
Merci d'avance aux ames charitables et surtout patientes!
Alexandre
1 réponse
GRRRRRRRRRRR
Que veux tu qu'on fasse de ca sans explication, mets ca dans ton message original, qu'on soit pas oblige de chercher toutes les infpos concernant un probleme dans plusieurs message, c'est le plus sur moyen que personne ne puisse t'aider parce que'on a pas le temps de tout lire!!!
ö,ö
\_/
Que veux tu qu'on fasse de ca sans explication, mets ca dans ton message original, qu'on soit pas oblige de chercher toutes les infpos concernant un probleme dans plusieurs message, c'est le plus sur moyen que personne ne puisse t'aider parce que'on a pas le temps de tout lire!!!
ö,ö
\_/