[mpich-discuss] How to use MPI::COMM::Gather & MPI::Op::Init(MPI_Op_create))

KongTao hawk_kongtao at yahoo.com.cn
Sat Apr 9 09:02:06 CDT 2011


hi, MPICH users
I have some problems on the function Gather and Op::Init
Gather: the function prototype is
void MPI::Comm::Gather(const void* sendbuf, int sendcount,const MPI::Datatype& sendtype, void* recvbuf,int recvcount, const MPI::Datatype& recvtype, int root) const = 0 
I don't know the difference between the second parameter( sendcount)and the fifth parameter(recvcount). can they be different?
Op::Init the function prototype is
void Init( User_function *, bool )
MPI_Op_create(MPI_User_function *, int ,MPI_Op*)

can you show me how to use User_function to define a user function? and where is the faults below?

-----------
void sumfunc(const void* x,void * y,int length,MPI::Datatype & dtype)
{
    int n=dtype.Get_size();
    for(int i=0;i<length;i++)
        *(y+n*i)=*(x+n*i)+*(y+n*i);
    return;
}

void op-test(){
    MPI::Op mysum;
    mysum.Init(sumfunc,true);
    int unit=pow(MPI::COMM_WORLD.Get_size(),3);
    int result1,result2;
    MPI::COMM_WORLD.Reduce(&unit,&resut1,1,MPI::INT,MPI::SUM,0);
    MPI::COMM_WORLD.Reduce(&unit,&resut2,1,MPI::INT,mysum,0);
    if(unit==0)
        cout<<"The results via sum&mysum are "<<result1<<" , "<<result2<<endl;
}


Thank you very much, waiting for your reply 

---
Kong Tao
School of Maths,Shandong Univ. P.R.C.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20110409/db3eae59/attachment-0001.htm>


More information about the mpich-discuss mailing list