1 year ago

#333744

test-img

zhuruihu1998

access violation error on FFTW and Armadillo

I'd like to use FFTW in Armadillo.My code is:

tuple<mat,mat> solver(mat charge)
{
    
    mat x = regspace(0, mesh_num - 1);
    mat xx = reshape(x, 1, mesh_num);
    mat xxx = repmat(xx, mesh_num, 1);
    mat y = regspace(0, mesh_num - 1);
    mat yy = reshape(y, mesh_num, 1);
    mat yyy = repmat(yy, 1, mesh_num);
    mat green_func = -0.5 * log(square(step_xc * xxx) + square(step_yc * yyy));
    green_func(0, 0) = 0;
    mat temp_1 = fliplr(green_func);
    mat temp_2 = temp_1.cols(0, mesh_num - 2);
    mat temp_3 = flipud(green_func);
    mat temp_4 = temp_3.rows(0, mesh_num - 2);
    mat temp_5 = fliplr(temp_4);
    mat temp_6 = temp_5.cols(0, mesh_num - 2);
    mat temp_7 = join_horiz(temp_6, temp_4);
    mat temp_8 = join_horiz(temp_2, green_func);
    mat green_func_expand = join_vert(temp_7, temp_8);
    int convolution_size = green_func_expand.n_rows + mesh_num - 1;
    mat temp_9 = join_horiz(green_func_expand, zeros(green_func_expand.n_rows, mesh_num - 1));
    mat green_func_conv = join_vert(temp_9, zeros(mesh_num - 1, convolution_size));
    mat temp_10 = join_horiz(charge, zeros(charge.n_rows, green_func_expand.n_rows - 1));
    mat charge_conv = join_vert(temp_10, zeros(green_func_expand.n_rows - 1, convolution_size));
    /*mat conv_result = step_xc*step_yc* real(ifft2(fft2(charge_conv) % fft2(green_func_conv)))/(2*datum::pi*datum::eps_0);*/
    fftw_complex* in_1 = reinterpret_cast<fftw_complex*>(charge_conv.memptr());
    fftw_complex* out_1 = (fftw_complex*)fftw_malloc((sizeof(fftw_complex) * convolution_size*convolution_size));
    fftw_plan p1 = fftw_plan_dft_2d(charge_conv.n_rows, charge_conv.n_cols, in_1, out_1, FFTW_FORWARD, FFTW_ESTIMATE);
    fftw_execute(p1);
    return make_tuple(green_func_conv,temp_9);
}

charge_cov is a matrix defined with Armadillo. I'd like to get the output of FFTW in the form of matrix of Armadillo. So I create a matrix charge_conv_fft first, then use reinterpret_cast to provide the pointer for out_1. But an error ocurrs reading 'An access violation occurred while writing location' which seems it can't write values in out_1. How to fix it?

c++

armadillo

fftw

0 Answers

Your Answer

Accepted video resources