【问题标题】:How to write MPI library for profiling如何编写用于分析的 MPI 库
【发布时间】:2019-03-12 15:27:14
【问题描述】:

例如,我想在用 C 编写的程序中调用所有 MPI_Sends 之前编写一个字符串。为此,我想编写一个分析库。我在 mylib.c 中编写了这段代码

#include <stdio.h>
#include <mpi.h>

int MPI_Send(void *buf, int count, MPI_Datatype type, int to, int tag, MPI_Comm comm)
{
    printf("Some string");
    return PMPI_Send(buf, count, type, to, tag, comm);
}

如果我运行mpicc -fPIC mylib.c -o mylib.o,我会得到错误-error: conflicting types for ‘MPI_Send’ 如何正确编写此代码以及如何编译并将其链接到我的 mpi 程序?

【问题讨论】:

标签: c shared-libraries mpi dynamic-linking


【解决方案1】:

您需要使用此签名声明您的函数:

int MPI_Send(const void* buf, int count, MPI_Datatype type, 
             int to, int tag, MPI_Comm comm) { ... }

第一个参数是const。 void* != const void*。这就是你所缺少的。在这里查看例如:https://www.mpich.org/static/docs/latest/www3/MPI_Send.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-05
    • 1970-01-01
    • 2014-11-19
    • 1970-01-01
    相关资源
    最近更新 更多