9.6. 编译MPI应用时的弃用警告
如果在编译MPI应用程序时看到弃用警告,那是因为您的应用程序使用了MPI中已弃用的符号/函数。例如:
shell$ mpicc deprecated-example.c -c
deprecated-example.c: In function 'foo':
deprecated-example.c:6:5: warning: 'MPI_Attr_delete' is deprecated: MPI_Attr_delete was deprecated in MPI-2.0; use MPI_Comm_delete_attr instead [-Wdeprecated-declarations]
MPI_Attr_delete(MPI_COMM_WORLD, 2);
^~~~~~~~~~~~~~~
In file included from deprecated-example.c:2:
/usr/local/openmpi/include/mpi.h:2601:20: note: declared here
OMPI_DECLSPEC int MPI_Attr_delete(MPI_Comm comm, int keyval)
^~~~~~~~~~~~~~~
请注意,弃用编译器警告会告诉你如何升级代码以避免弃用警告。在这个例子中,它建议你使用MPI_Comm_delete_attr()而不是MPI_Attr_delete()。
另外请注意,即使Open MPI配置了--enable-mpi1-compatibility来重新启用已移除的MPI-1符号,当您使用这些已移除的符号时,仍然会收到编译器警告。
以下列出了MPI中已被弃用的函数及其替代函数。部分函数已被弃用并从MPI规范中移除,这些函数列在此处。
已弃用的符号 (点击查看详情,见下方) |
替换为 (点击跳转至对应手册页) |
弃用该符号的MPI版本 |
|---|---|---|
MPI-2.0 (1996) |
||
MPI-2.0 (1996) |
||
MPI-2.0 (1996) |
||
MPI-2.0 (1996) |
||
MPI-2.0 (1996) |
||
MPI-2.0 (1996) |
||
MPI-2.0 (1996) |
||
MPI-2.2 (2009) |
||
MPI-2.2 (2009) |
||
MPI-2.2 (2009) |
||
MPI-4.0 (2021) |
||
MPI-4.0 (2021) |
||
Fortran 内置函数 `c_sizeof` 或 |
MPI-4.0 (2021年) |
9.6.1. MPI_Keyval_create
MPI_Keyval_create 已被弃用,现由 MPI_Comm_create_keyval 替代。新函数的C语言绑定与已弃用版本完全相同。因此,应用程序只需直接替换被调用的函数即可。
Fortran绑定的不同之处在于,extra_state参数在新接口中是一个地址大小的整数(而旧接口中是常规整数)。此外,复制和删除回调函数的Fortran绑定与地址大小的属性保持一致。
USE mpi
EXTERNAL my_copy_attr_function
EXTERNAL my_copy_delete_function
INTEGER ierror
INTEGER comm_keyval
INTEGER old_extra_state
INTEGER(KIND=MPI_ADDRESS_KIND) new_extra_state
! Old way
CALL MPI_KEYVAL_CREATE(my_copy_attr_function, my_copy_delete_function,
comm_keyval, old_extra_state, ierror)
! New way
CALL MPI_COMM_CREATE_KEYVAL(my_copy_attr_function, my_delete_attr_function,
comm_keyval, new_extra_state, ierror)
9.6.2. MPI_Keyval_free
MPI_Keyval_free 和 MPI_Comm_free_keyval 的绑定在C和Fortran中是相同的。用户可以直接用新版本替换已弃用的函数。
9.6.3. MPI_Copy_function 和 MPI_Delete_function
MPI_Copy_function 和 MPI_Delete_function 仅用于已弃用的函数 MPI_Keyval_create(),如 MPI_COMM_CREATE_KEYVAL 中所述。
对于C代码,开发者可以直接使用新的完全等效的类型名称(即返回类型、参数数量和类型未改变)MPI_Comm_copy_attr_function和MPI_Comm_delete_attr_function。
对于Fortran应用程序,唯一的区别在于extra_state参数所需的整数类型,现在必须是一个地址大小的整数。
9.6.4. MPI_Attr_put
已弃用的MPI_Attr_put的C语言绑定与其替代品MPI_Comm_set_attr完全相同。Fortran绑定的区别在于:新的MPI_Comm_set_attr中使用的是带地址大小的整数作为属性值,而MPI_Attr_put中使用的是常规整数。
USE mpi
INTEGER ierror
INTEGER comm_keyval
INTEGER old_attr_val
INTEGER(KIND=MPI_ADDRESS_KIND) new_attr_val
! Old way
CALL MPI_ATTR_PUT(MPI_COMM_WORLD, comm_keyval,
old_attr_val, ierror)
! New way
CALL MPI_COMM_SET_ATTR(MPI_COMM_WORLD, comm_keyval,
new_attr_val, ierror)
9.6.5. MPI_Attr_get
新旧接口的C语言绑定是相同的。Fortran绑定的区别在于,新的MPI_Comm_get_attr中使用地址大小的整数作为属性值,而MPI_Attr_get中使用常规整数。
9.6.6. MPI_Attr_delete
C和Fortran语言中,MPI_Attr_delete与MPI_Comm_delete_attr的绑定方式完全相同,因此开发者可以直接用一个函数调用替换另一个。
9.6.7. MPI_Info_get
应用程序应使用MPI_Info_get_string替代MPI_Info_get,但用法略有不同。请参阅以下示例。
MPI_Info info;
// Create an info object using MPI_Info_create()
...
// Retrieve the the value of a provided key later in the code
char key[] = "my_key";
char value[64];
int valuelen=64;
int flag;
// Old way
MPI_Info_get(info, key, valuelen, &value, &flag);
// New way
// Note that we pass the address of valuelen with
// the new interfaces, since the variable will
// contain the length of the value string after
// the function call.
MPI_Info_get_string(info, key, &valuelen, &value, &flag);
}
9.6.8. MPI_Info_get_valuelen
MPI_Info_get_valuelen 已被弃用,因为新函数
MPI_Info_get_string 也会返回值字符串的长度。
请参考 MPI_INFO_GET 中展示的示例。
9.6.9. MPI_Sizeof
Fortran中的MPI_SIZEOF结构已被弃用,因为可以使用标准的Fortran语言结构如c_sizeof和storage_size来替代。
9.6.10. MPI_Comm_errhandler_fn, MPI_File_errhandler_fn, MPI_Win_errhandler_fn
以下函数类型定义已被弃用,并由新名称取代。除了类型定义名称外,函数签名完全相同;更新名称是为了与其他函数类型定义名称的约定保持一致。
MPI_Comm_errhandler_fn→MPI_Comm_errhandler_functionMPI_File_errhandler_fn→MPI_File_errhandler_functionMPI_Win_errhandler_fn→MPI_Win_errhandler_function