[mpich-discuss] Help with the source file

Nicolas Rosner nrosner at gmail.com
Mon Apr 11 14:10:12 CDT 2011


Like I said, I'm not familiar with the C++ bindings for user-defined
reduction ops, but this still looks like invalid or at least very
risky pointer arithmetic (at the language level, i.e. not a
MPI-specific problem but a basic C++ one).

Are you sure you should be using void for x and y? You could probably
pull this off by adding more and more cast operators, but why do
everything yourself from scratch at the single-byte level? Any good
reason to annihilate type-safety instead of helping the compiler help
you?

Regards
N.



On Sat, Apr 9, 2011 at 11:08 AM, KongTao <hawk_kongtao at yahoo.com.cn> wrote:
> I Write the following  MPI source file binding with c++, it is error ,why ?
> can anyone help me to fix it?
>
> -----
> void sumfunc(const void* x,void * y,int length,const 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,&result1,1,MPI::INT,MPI::SUM,0);
>     MPI::COMM_WORLD.Reduce(&unit,&result2,1,MPI::INT,mysum,0);
>     if(unit==0)
>         cout<<"The results via sum&mysum are "<<result1<<" ,
> "<<result2<<endl;
> }
>
> Thank you very much!
>
> ---
> Kong Tao
> School of Maths,Shandong Univ. P.R.C.
>
> _______________________________________________
> mpich-discuss mailing list
> mpich-discuss at mcs.anl.gov
> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
>
>


More information about the mpich-discuss mailing list