|
|
Madhuri wrote:
Can somebody give an example of the use of MPI_MINLOC with
MPI_Reduce.
Take a look at the MPI_Reduce man page. There should be a discussion
of MPI_MINLOC. It needs value/index pairs.
And move from LAM to Open MPI.
In my program i have the following program:
#include
#include"mpi.h"
#include
int fun(int x[]);
int main(int argc,char* argv[])
{
int x[6],mr,np,i,best;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&mr);
MPI_Comm_size(MPI_COMM_WORLD,&np);
//MPI_Status stat;
for(i=0;i<5;i++)
{
x[i]=i+mr*5;
}
x[6]=fun(x);
MPI_Reduce(&x[6],&best,1,MPI_INT,MPI_MINLOC,0,MPI_COMM_WORLD);
if(mr==0)
{
printf("minloc= %d",best);
}
MPI_Finalize();
return 0;
}
int fun(int x[])
{
int i,sum=0;
for(i=0;i<5;i++)
{
sum=sum+x[i]*x[i];
}
return sum;
}
When i run this program, it shows the error message "MPI_Reduce:
invalid operation (rank 0, MPI_COMM_WORLD)
Rank (0, MPI_COMM_WORLD): Call stack within LAM:
Rank (0, MPI_COMM_WORLD): - MPI_Reduce()
Rank (0, MPI_COMM_WORLD): - main()"
Can somebody help me on it??????????
Madhuri
Research Scholar
Department of Mathematics
IIT Roorkee
_______________________________________________
This list is archived at http://www.lam-mpi.org/MailArchives/lam/
|
|
|