MPI_Op_creat[编译错误求助]
admin 发表于 2010-06-01 | 来源:互联网 | 阅读:

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

typedef struct

{

double real,imag;

} complex;

void cprod(complex *in,complex *inout,int* len,MPI_Datatype *dptr)

{

int i;

complex c;

for(i=0;i<*len;++i)

{

c.real=(*in).real*(*inout).real-(*in).imag*(*inout).imag;

c.imag=(*in).real*(*inout).imag+(*in).imag*(*inout).real;

*inout=c;

in++;

inout++;

}

}

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

{

int rank;

int root;

complex source,result;

MPI_Op myop;

MPI_Datatype ctype;

MPI_Init(&argc,&argv);

MPI_Comm_rank(MPI_COMM_WORLD,&rank);

MPI_Type_contiguous(2,MPI_DOUBLE,&ctype);

MPI_Type_commit(&ctype);

MPI_Op_create(cprod,true,&myop);

root=2;

source.real=rank+1;

source.imag=rank+2;

MPI_Reduce(&source,&result,1,ctype,myop,root,MPI_COMM_WORLD);

if(rank==root) fprintf(stderr,"P:%d result is %lf + %lfi\n",rank,result.real,result.imag);

MPI_Finalize();

}
——————————————————————————————————————————————————————————–
以上是照着书编的。但是编译提示出错。检查了好久,都不知道为什么出错,以下是错误信息:
error C2664: ‘MPI_Op_create’ : cannot convert parameter 1 from ‘void (__cdecl *)(complex *,complex *,int *,MPI_Datatype *)’ to ‘MPI_User_function (__cdecl *)’
None of the functions with this name in scope match the target type

————————————————————————————————————————————————————————————
刚学,盼解答~

已经有2 个评论
  1. xjhuc05 说:

    有么有知道的啊。。。。

  2. WOOMYWOODY 说:

    知道了一种解决方法。。改成:MPI_Op_creat((MPI_User_function*)cprod,true,&myop);就正确了。。但是清华的《高性能计算之并行编程技术》上及网上找的外文参考资料里都没加MPI_User_function*. 是不是我哪里没做对?

我要评论

评论功能因故关闭!

请加入我们的QQ群一起参与讨论:群号59400482(500人超级群)


返回首页 | 关于我们 | 联系我们 | 广告合作 | 网站地图 | 友情链接 | 版权声明