我正在尝试在iceemdan()
中开发函数eemd.c
,但是现在我遇到了iceemdan()
附加部分最后一行中的分段错误。我将GCC与GSL和Glib一起使用(我也在使用OpenMP,但我的VirtualBox仅分配了一个核心)。 GDB的回溯,并且在一些重要的变量的一些打印malloc()
显示:
(gdb) backtrace
#0 _int_malloc (av=av@entry=0x7ffff7baac40 <main_arena>,bytes=bytes@entry=143856) at malloc.c:4086
#1 0x00007ffff7a5bc23 in __GI___libc_malloc (bytes=143856) at malloc.c:3041
#2 0x0000555555556980 in iceemdan (input=0x55555555d260, N=999, output=0x5555555603e0, M=9, ensemble_size=2, noise_strength=0.02, S_number=4, num_siftings=50, rng_seed=0) at src/eemd1.c:592
#3 0x00005555555554d5 in main () at src/eemd1.c:56
(gdb) p bytes
$1 = 143856
(gdb) p remainder_size
$2 = <optimized out>
(gdb) p MINSIZE
No symbol "MINSIZE" in current context.
(gdb) p size
$3 = <optimized out>
(gdb) p nb
$4 = 143872
(gdb) p victim
$5 = (mchunkptr) 0x555555573c10
(gdb) p chunksize(victim)
No symbol "chunksize" in current context.
(gdb) p remainder
$6 = (mchunkptr) 0x555555596e10
(gdb) p remainder_size
$7 = <optimized out>
(gdb) p size
$8 = <optimized out>
(gdb) p nb
$9 = 143872
此代码为:
#include <math.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_sf_trig.h>
#include "eemd.h"
const size_t ensemble_size0 = 2;//50;
const unsigned int S_number0 = 4;
const unsigned int n_siftings = 50;
const double noise_strength0 = 0.02;
const unsigned long int rng_seed0 = 0;
const char outfile[] = "iceemdan_example.out";
const size_t N0 = 999;
int main(void) {
libeemd_error_code err;
double* inp = malloc(N0*sizeof(double));
memset(inp, 0x00, N0*sizeof(double));
for (size_t i=0; i<1000; i++) {
inp[i] = i; // Something to make compilable: program has more complex
}
size_t M = emd_num_imfs(N0);
double* outp = malloc(M*N0*sizeof(double));
// Run ICEEMDAN
err = iceemdan(inp, N0, outp, M, ensemble_size0, noise_strength0, S_number0, n_siftings, rng_seed0);
}
inline static void array_mult(double* dest, size_t n, double val) {
for (size_t i=0; i<n; i++)
dest[i] *= val;
}
inline static void array_mult(double* dest, size_t n, double val) {
for (size_t i=0; i<n; i++)
dest[i] *= val;
}
// Define iceemdan()
libeemd_error_code iceemdan(double const* restrict input, size_t N, double* restrict output, size_t M, unsigned int ensemble_size, double noise_strength, unsigned int S_number, unsigned int num_siftings, unsigned long int rng_seed) {
gsl_set_error_handler_off();
// Standardize input variance
const double sd = gsl_stats_sd(input, 1, N);
double* sinput = malloc(N*sizeof(double));
array_copy(input, N, sinput);
array_mult(sinput,N,1.0/sd);
// Validate parameters
// ...
const double one_per_ensemble_size = 1.0/ensemble_size;
// Initialize output data to zero
memset(output, 0x00, M*N*sizeof(double));
// Storage for white noise modes
double* wnmodes = malloc(M*ensemble_size*N*sizeof(double));
}
make文件是:
.PHONY: all
gsl_flags := $(shell pkg-config --libs --cflags gsl) -DHAVE_INLINE commonflags := -Wall -Wextra -std=c99 -pedantic -Wno-unknown-pragmas -Wshadow -Wpointer-arith
commonflags += $(CFLAGS)
all: eemd1
eemd1: src/eemd1.c
gcc $(commonflags) -ggdb -I../src $^ -L.. -Wl,-rpath,.. $(gsl_flags) -leemd -o $@
GCC命令解析为:
gcc -Wall -Wextra -std=c99 -pedantic -Wno-unknown-pragmas -Wshadow -Wpointer-arith -ggdb -I../src src/eemd1.c -L.. -Wl,-rpath,.. -lgsl -lgslcblas -lm -DHAVE_INLINE -leemd -o eemd1