编译MPI C代码时出错!“未定义符号:ompi_mpi_int“

2024-09-29 23:22:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用SWIG包装器编译mpic代码,以实现Python接口。通过搜索StackOverflow和google,我知道这是SWIG包装过程中的链接问题,但我无法找到解决问题的方法。在

我用以下代码行编译:

>swig -python worker_c.i
>mpicc -fPIC $(python-config --includes) -c worker_c.c worker_c_wrap.c
>ld -zmuldefs -shared worker_c.o worker_c_wrap.o -o _worker_c.so

导入生成的worker_c.py会产生以下结果:

^{pr2}$

以下是我的源代码:

工人薪酬

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

const int nelements1 = 1E3;
const int nelements2 = 1E6;

int outarray(){
    float* array = malloc(sizeof(float) * nelements2);
    int i = 0;
    for( i = 0; i < nelements2; i++ ){
        array[i] = 1.110001;
    }

    return *array;
}

int main(int argc, char *argv[]){

MPI_Comm comm;
MPI_Comm_get_parent(&comm);

int myid, world_size;//, size;
int root = 0;
int* endloop = malloc(sizeof(int));
void* input = malloc(sizeof(float) * nelements1);
void* output;
void* sendbuff;
int recv = 1;

MPI_Comm_rank(MPI_COMM_WORLD, &myid);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);

output = (void *)outarray();

MPI_Scatter(sendbuff, recv, MPI_INT, endloop, recv, MPI_INT, root, comm);

while ( endloop[0] < 1) {
    MPI_Barrier(comm);
    MPI_Scatter(sendbuff, recv, MPI_FLOAT, input, nelements1, MPI_FLOAT, root, comm);
    MPI_Barrier(comm);
    MPI_Gather(sendbuff, recv, MPI_FLOAT, output, nelements2, MPI_FLOAT, root, comm);
    MPI_Scatter(sendbuff, recv, MPI_INT, endloop, recv, MPI_INT, root, comm);
}

free(endloop);
free(input);

MPI_Finalize();
}

工人姓名

// file: worker_c.i
%module worker_c
%{
#include <mpi.h>
#include <stdlib.h>
#include "worker_c.c"
%}

%include mpi4py/mpi4py.i
%mpi4py_typemap(Comm, MPI_Comm);
void outarray();
void main(int argc, char *argv[]);

我在SWIG和MPI方面没有什么经验,所以我希望能得到任何帮助。 谢谢您!在


Tags: sizeincluderootfloatintworkercommmpi

热门问题