我有一段代码,用于在使用-pg -ggdb编译时运行良好,但我现在无法找到导致它崩溃的原因。省略这两个选项使它运行得很好。有什么可能导致它的线索?
这是对gcc
的调用gcc -std=gnu99 -fopenmp -pg -O0 main.c Simulation.c Lattice.c Substrate.c
Adsorbate.c -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -L/usr/local/atlas/lib
-I/usr/local/atlas/include/ -I/usr/local/include -L/usr/local/lib -lgsl -lgslcblas
-lglib-2.0 -lm
调用gcc,例如运行代码是
gcc -std=gnu99 -fopenmp -fexpensive-optimizations -ffast-math -fomit-frame-pointer
-O3 -mmmx -msse -msse2 -msse3 -mfpmath=sse -march=corei7 -mtune=corei7 main.c
Simulation.c Lattice.c Substrate.c Adsorbate.c -I/usr/include/glib-2.0 -I/usr/lib6
/glib-2.0/include -L/usr/local/atlas/lib -I/usr/local/atlas/include/ -I/usr/loca
/include -L/usr/local/lib -lgsl -lgslcblas -lglib-2.0 -lm
这是main.c文件的开头:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Lattice.h"
#include "Substrate.h"
#include "Adsorbate.h"
#include "Simulation.h"
#include <glib.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>
#include <assert.h>
#include <omp.h>
/* Units are:
* [x] = Angstrom
* [m] = amu
* [t] = psec
* [T] = K
*
* 1[x]/[t] = 100 m/sec 1m/sec = 0.01 [x]/[t]
* 1[E] = 1.03584E-4 eV 1eV = 9654 [E]
* 1[F] = 1.66E-13 N 1N = 602.41E10 [F]
*
* k = 9036.1446 [F]/[x]
* Kb = 0.83192 [E]/[T]
* A = 1303.3[E]
* b = 0.875 1/[x]
* R0 = 3.3 [x]
*
*/
int main(int argc, char **argv)
{
// Start simulation
int numcores = omp_get_num_procs(); // get number of available processors
omp_set_num_threads(numcores-1); // leave one core free
struct Parameters * P;
struct Lattice * restrict lfcc ;
lfcc = (struct Lattice*)malloc(sizeof(struct Lattice));
P = (struct Parameters*)malloc(sizeof(struct Parameters));
if (argc<2) {fprintf(stderr,"\n*****\tPlease supply in the command line a Perameters file\t*****\n"); exit(1);}
char * pfile = argv[1];
Init_Simulation(lfcc, P, argc, pfile);
答案 0 :(得分:1)
故障在以下函数中,该函数接受glib要解析的文件以从用户获取一些参数。注释掉的行是bug隐藏的行。因为我不需要它们(它们之前被插入进行测试)我删除它们并且代码运行正常。
void Get_Data_File(char * datafile, struct Parameters * P)
{
P->Datafile = g_key_file_new ();
g_key_file_load_from_file (P->Datafile, datafile, 0, NULL);
// char ** Groups;
// size_t * l;
// Groups = g_key_file_get_groups (P->Datafile, l);
// int k = 0;
// char * group = Groups[0];
}