包括 mpif.h,错误 c2015 常量中的字符过多

include mpif.h, error c2015 too many characters in constant

我正在尝试测试来自 Whosebug () 的 MPI 共享内存示例的代码。在这里,我将 post 整个代码作为最小可重现示例。

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

typedef struct MyArray {
    double* data;
    int length;
}MyArray;

#define ARRAY_SIZE 10

int main(int argc, char *argv[]) {
    int rank, worldSize, i;
    MPI_Win win;
    MPI_Aint disp;
    MPI_Aint *allProcessDisp;
    MPI_Request *requestArray;

    MyArray myArray;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &worldSize);

    MPI_Win_create_dynamic(MPI_INFO_NULL, MPI_COMM_WORLD, &win);

    allProcessDisp = malloc(sizeof(MPI_Aint) * worldSize);

    requestArray = malloc(sizeof(MPI_Request) * worldSize);
    for (i = 0; i < worldSize; i++) 
        requestArray[i] = MPI_REQUEST_NULL;

    myArray.data = malloc(sizeof(double) * ARRAY_SIZE);
    myArray.length = ARRAY_SIZE;

    //Allocating memory for each process share window space 
    MPI_Alloc_mem(sizeof(double) * ARRAY_SIZE, MPI_INFO_NULL, &myArray.data);
    for (i = 0; i < ARRAY_SIZE; i++)
        myArray.data[i] = rank;

    //attach the allocating memory to each process share window space 
    MPI_Win_attach(win, myArray.data, sizeof(double) * ARRAY_SIZE);

    MPI_Get_address(myArray.data, &disp);

    if (rank == 0) {
        allProcessDisp[0] = disp;
        //Collect all displacements
        for (i = 1; i < worldSize; i++) {
            MPI_Irecv(&allProcessDisp[i], 1, MPI_AINT, i, 0, MPI_COMM_WORLD, &requestArray[i]);
        }
        MPI_Waitall(worldSize, requestArray, MPI_STATUS_IGNORE);
        MPI_Bcast(allProcessDisp, worldSize, MPI_AINT, 0, MPI_COMM_WORLD);
    }
    else {
        //send displacement 
        MPI_Send(&disp, 1, MPI_AINT, 0, 0, MPI_COMM_WORLD);
        MPI_Bcast(allProcessDisp, worldSize, MPI_AINT, 0, MPI_COMM_WORLD);
    }

    // here you can do RMA operations 
    // Each time you need an RMA operation you start with 
    double otherRankData = -1.0;
    int otherRank = 1;
    if (rank == 0) {
        MPI_Win_lock_all(0, win);
        MPI_Get(&otherRankData, 1, MPI_DOUBLE, otherRank, allProcessDisp[otherRank], 1, MPI_DOUBLE, win);
        // and end with 
        MPI_Win_unlock_all(win);
        printf("Rank 0 : Got %.2f from %d\n", otherRankData, otherRank);
    }

    if (rank == 1) {
        MPI_Win_lock_all(0, win);
        MPI_Put(myArray.data, ARRAY_SIZE, MPI_DOUBLE, 0, allProcessDisp[0], ARRAY_SIZE, MPI_DOUBLE, win);
        // and end with 
        MPI_Win_unlock_all(win);
    }

    printf("Rank %d: ", rank);
    for (i = 0; i < ARRAY_SIZE; i++)
        printf("%.2f ", myArray.data[i]);
    printf("\n");

    //set rank 0 array
    if (rank == 0) {
        for (i = 0; i < ARRAY_SIZE; i++)
            myArray.data[i] = -1.0;

        printf("Rank %d: ", rank);
        for (i = 0; i < ARRAY_SIZE; i++)
            printf("%.2f ", myArray.data[i]);
        printf("\n");
    }

    free(allProcessDisp);
    free(requestArray);
    free(myArray.data);

    MPI_Win_detach(win, myArray.data);
    MPI_Win_free(&win);
    MPI_Finalize();

    return 0;
}

我使用 Visual Studio C++ 2012 和 HPC Pack 2012 MS-MPI Redistributable Package。编译时报错

error C3861: 'MPI_Win_attach': identifier not found
error C3861: 'MPI_Win_lock_all': identifier not found
error C3861: 'MPI_Win_unlock_all': identifier not found
error C3861: 'MPI_Win_lock_all': identifier not found
error C3861: 'MPI_Win_unlock_all': identifier not found
error C3861: 'MPI_Win_detach': identifier not found

我搜索了 MS MPI 参考资料 (https://docs.microsoft.com/en-us/message-passing-interface/mpi-win-attach-function),它似乎也需要 mpif.h 当我使用

#include "mpif.h"

它有很多错误,例如

Error   51  error C2015: too many characters in constant

仔细看mpif.h中的错误部分,是这样的

   INTEGER MPI_OFFSET
   PARAMETER (MPI_OFFSET=z'4c00083c')
   INTEGER MPI_COUNT
   PARAMETER (MPI_COUNT=z'4c00083d')
   INTEGER MPI_FLOAT_INT
   PARAMETER (MPI_FLOAT_INT=z'8c000000')
   INTEGER MPI_DOUBLE_INT
   PARAMETER (MPI_DOUBLE_INT=z'8c000001')
   INTEGER MPI_LONG_INT
   PARAMETER (MPI_LONG_INT=z'8c000002')
   INTEGER MPI_SHORT_INT
   PARAMETER (MPI_SHORT_INT=z'8c000003')
   INTEGER MPI_LONG_DOUBLE_INT
   PARAMETER (MPI_LONG_DOUBLE_INT=z'8c000004')

我认为我不应该将 mpif.h 的 ' 更改为 ",因为它是一个库 header。有什么方法可以抑制此编译错误并使其正常工作吗?谢谢。

@Zulan 关于 mpif.h 适用于 Fortran 的说法是正确的。所以不能包括 mpif.h.

问题似乎出在MS MPI 版本程序上。我将 MS MPI SDK 从 9.0 升级到 10.0 (https://www.microsoft.com/en-us/download/details.aspx?id=57467),问题解决了。