我想并行化一个数值积分函数。我想在计算过程中使用这个函数。之前的工作应该在根进程中完成。这可以在 MPI 中完成吗?
double integral_count_MPI(double (*function)(double) , double beginX, double endX, int count)
{
double step, result;
int i;
if (endX - beginX <= 0) return 0;
step = (endX - beginX) / count;
result = 0;
double *input = (double*)malloc((count+1) *sizeof(double));
for (i = 0; i <= count; i ++)
{
input[i] = beginX + i*step;
}
// Calculate and gather
}
编辑
算法:
1 process calculation;
while:
1 process calculation;
integration very complex function with many processes;
1 process calculation;
end while;
1 process calculation;