【发布时间】:2015-07-15 04:00:11
【问题描述】:
我正在尝试在皮质 M4 核上乘以任意大小的矩阵。我确实需要一个malloc... 但我不明白为什么在第一次通话时它起作用,而在第二次通话时它不再起作用。它只是跳转到默认的中断处理程序 FaultISR。
特此反汇编代码:
执行BL命令失败
函数调用:
multiplyMatrices( &transFRotMatrix[0][0],3, 3, &sunMeasurements[0][0], 3, 1, *orbitalSunVector); //Works fine
multiplyMatrices( &firstRotMatrix[0][0],3, 3, &orbitalTMFV[0][0], 3, 1, *inertialTMFV); //doesn t work fine
代码:
void multiplyMatrices(float *transposedMatrix, int height1, int width1, float *iSunVector,int height2, int width2, float *orbitalSunVector)
{
int y=0;
int x = 0;
int row=0;
int column =0;
int k=0;
int k2=0;
float result = 0;
float *output2=NULL;
int i=0;
int j=0;
i=0;
k=0;
k2 = 0;
if(width1 != height2)
{
//printf("unmatching matrices, error.\n\n");
return;
}
output2 = malloc(height1 * width2 * sizeof(float)); //<---- jumps o FaultISR
while(k<width1) //aantal rijen 1ste matrix
{
for(j=0;j<height2;j++) //aantal rijen 2de matrix
{
result += (*((transposedMatrix+k*width1)+j)) * (*((iSunVector+j*width2)+k2)); //1ste var:aantal kolommen 2de matrix --2de variabele na de plus = aantal kolommen 2de matrix
//printf("%f * %f\t + ", (*((transposedMatrix+k*width1)+j)), (*((iSunVector+j*width2)+k2)));
}
output2[row* width1 + column] = result;
k2++;
x++;
column++;
if(x==width2) //aantal kolommen 2de Matrix
{
k2=0;
x=0;
column=0;
row++;
y++;
k++;
}
result = 0;
}
//tussenresultaat
for(i=0;i<height1;i++)
{
for(j=0;j<width2;j++)
{
orbitalSunVector[j * height1 + i] = output2[i* width1 + j]; //output2[i][j];
}
}
free(output2);
}
【问题讨论】:
-
height1和width2的值是多少?也许你的内存不足?也许你写的超出了(或其他一些)分配的内存? -
不应失败,除非堆栈和堆没有正确设置,即使 height1 和 width2 太大,它也应该返回 NULL(如果它们的乘积为负数,情况相同)
-
你可以在函数调用中看到这些变量的值
-
所以你要分配
3 * 3 * sizeof(float)? 为什么你不能这样做,例如float output[9]? -
因为这不是动态的,并且不适用于任何大小的矩阵