【发布时间】:2021-08-10 19:11:36
【问题描述】:
我正在编写使用 PMPI(Profile MPI 接口)分析 MPI 代码的示例代码。 虽然 C 中的示例运行良好,但类似 Fortran 的简单代码无法运行。
这是我的 C 代码:
#include "mpi.h"
#include <stdio.h>
int main (int argc, char *argv[]) {
int size;
int rank;
char b[100];
MPI_Status st;
MPI_Init (&argc, &argv);
MPI_Pcontrol(2);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0) {
MPI_Send(b, 100, MPI_CHAR, 1, 99, MPI_COMM_WORLD);
} else {
MPI_Recv(b, 100, MPI_CHAR, 0, 99, MPI_COMM_WORLD, &st);
}
MPI_Finalize();
return 0;
}
分析代码捕获对 MPI_Xxx 函数的调用:
#include "mpi.h"
#include <stdio.h>
static int totalBytes = 0;
int MPI_Init (int *argc, char ***argv) {
int err = PMPI_Init(argc, argv);
return err;
}
int MPI_Send(const void* buffer, int count, MPI_Datatype datatype,
int dest, int tag, MPI_Comm comm) {
int size;
printf("Sending ...\n");
int result = PMPI_Send(buffer, count, datatype, dest, tag, comm);
MPI_Type_size(datatype, &size);
totalBytes += count*size;
return result;
}
int MPI_Finalize() {
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0) {
printf("Total bytes: %d\n", totalBytes);
}
return PMPI_Finalize();
}
编译命令为:
$ mpicc -c example.c
$ mpicc -c prof.c
$ mpicc -o example prof.o example.o
$ mpiexec --hostfile hfile --oversubscribe -np 2 ./example
如预期的那样,输出包括以下句子:
Sending ...
Total bytes: 100
在fortran中,代码是:
PROGRAM send_recv_mpi
include 'mpif.h'
integer process_Rank, size_Of_Cluster, ierror, message_Item
call MPI_INIT(ierror)
call MPI_COMM_SIZE(MPI_COMM_WORLD, size_Of_Cluster, ierror)
call MPI_COMM_RANK(MPI_COMM_WORLD, process_Rank, ierror)
IF(process_Rank == 0) THEN
message_Item = 42
call MPI_SEND(message_Item, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, ierror)
print *, "Sending message containing: ", message_Item
ELSE IF(process_Rank == 1) THEN
call MPI_RECV(message_Item, 1, MPI_INT, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierror)
print *, "Received message containing: ", message_Item
END IF
call MPI_FINALIZE(ierror)
END PROGRAM
编译是:
$ mpicc -c prof.c
$ mpif77 -c simple.f90
$ mpif77 -o simple prof.o simple.o
$ mpiexec --hostfile hfile --oversubscribe -np 2 ./simple
但是,Fortran 执行不显示分析消息。好像没有调用分析代码。
非常感谢。
【问题讨论】:
-
您认为应该采用什么机制来启用 Fortran 版本中的分析调用?除了“正常”
MPI_INIT等之外,您似乎没有打电话给其他任何人。 -
我以为 Fortran 中的 MPI_INIT 只是 MPI_Init 的 C MPI 实现的接口,我想使用配置文件接口捕获调用。
-
事实上,我将 MPI_Init() 重写为 mpi_init_() 并 Fortran 调用它。也就是说,MPI_INIT 在我的平台中调用 mpi_init_。在 mpi_init_ 中,我调用 PMPI_Init(NULL, NULL) 并且运行良好,但对于像 mpi_send_ 这样更复杂的函数,我在调用 PMPI_Send 和参数时遇到问题。实际上,我不知道该怎么做。