I have some code written in C++ that compiles and runs fine (with reasonable output) when using g++, but when I try to use mpic++, I get a runtime bus error. I've managed to figure out where the bus error is occuring, but not why. Here is my code:
one = (double *) malloc(sizeof(&one) * nx * nx * nt);
two = (double **) malloc(sizeof(&two) * nx * nx);
rho_exp = (double ***) malloc(sizeof(&rho_exp) * nx);
for(i = 0; i < nx * nx; i++)
two[i] = &one[i * nt];
for(i = 0; i < nx; i++)
rho_exp[i] = &two[i * nx];
for(i = 0; i < nx; i++)
for(j = 0; j < nx; j++)
for(k = 0; k < nt; k++)
rho_exp[i][j][k] = 0;
The bus error is occurring during the three nested for loops. My question is two-fold: One, I assume, I've screwed up my allocation for the 3D matrix; how should I have done it? Two, why did this work with gcc and g++, but not with mpic++?