在编写MPI程序时,我一直使用malloc来分配动态内存,例如:
然而,我遇到了这个MPI函数:
int main(int argc, char* argv[]) {
MPI_Init(&argc, &argv);
int arr_size = 10;
int* arr = malloc( sizeof(int) * arr_size );
// do some MPI stuff
MPI_Finalize();
}
然而,我遇到了这个MPI函数:
MPI_Alloc_mem
,链接在这里:
https://www.mpich.org/static/docs/v3.2/www3/MPI_Alloc_mem.html
但我不确定它是用来做什么的。何时应该使用malloc,何时应该使用MPI_Alloc_mem
呢?
阅读了这篇文章之后:http://mpi.deino.net/mpi_functions/MPI_Alloc_mem.html,似乎MPI_Alloc_mem主要用于远程内存访问。为什么不直接使用malloc呢?我找不到任何答案说明何时选择MPI_Alloc_mem
而不是malloc
。