You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Fortran中能否向MPIO子例程传递NULL参数?MPI标准示例疑问

Answers to Your Fortran MPI Questions

Great questions! Let's break this down clearly, since Fortran's MPI bindings handle "NULL-like" arguments a bit differently from C.

1. Can you pass NULL-like arguments to MPIO subroutines in Fortran?

Fortran doesn’t have a direct equivalent to C’s NULL pointer, but MPI’s Fortran bindings provide specific constants and rules to achieve the same effect when arguments are irrelevant to a process:

  • For buffer arguments: When a buffer isn’t needed (e.g., non-root processes in gather operations), you can pass MPI_BOTTOM—this is an MPI-defined address constant that acts like C’s NULL for buffer parameters.
  • For datatype arguments: Use MPI_DATATYPE_NULL exactly like you would in C when the datatype parameter is meaningless for the current process.
  • Critical note: You can only use these values for parameters explicitly marked as optional or process-dependent in the MPI standard. Always check the subroutine’s spec before using these "empty" values.

2. Can Fortran replicate the MPI_Gatherv call from MPI 3.1 Example 4.23?

Absolutely! The C example uses NULL for arguments that only matter to the root process. Fortran can mirror this behavior perfectly with MPI’s special constants:

For non-root processes, the equivalent Fortran call would be:

call MPI_GATHERV(lbuf, position, MPI_PACKED, MPI_BOTTOM, 0, 0, MPI_DATATYPE_NULL, root, comm, ierr)

Let’s break down the substitutions for the C NULL arguments:

  • MPI_BOTTOM replaces the NULL receive buffer (non-root processes don’t receive data, so this parameter is irrelevant).
  • We pass 0 for the receive count and displacement arguments—MPI allows this when these values don’t apply to the process.
  • MPI_DATATYPE_NULL matches the C version’s MPI_DATATYPE_NULL for the receive datatype parameter.

Just like in the C example, the root process must still provide valid values for all receive-side arguments—only non-root processes can use these "empty" placeholders.

内容的提问来源于stack exchange,提问作者Ray

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:18:07