I am new to MPI program.Please help me to correct the correct the
code.If there's an error please write your comment why its so.Thanks
for your help!
_________________________________________________________________
#include <stdio.h>
#include "mpi.h"
#define MAXSIZE 20
main(int argc, char *argv[])
{
int myid, numprocs, localresult, result[MAXSIZE];
int i, tag, final;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
if ( numprocs > MAXSIZE )
{
if ( myid == 0 )
printf("The number of processes must be less than %d\n",
MAXSIZE);
exit(0);
}
final = 0;
for ( i = 0; i < numprocs; i++)
result[i] = i;
MPI_Scatter(result, numprocs, MPI_INT, &localresult, 1, MPI_INT, 0,
MPI_COMM_WORLD);
if( myid )
{
localresult = localresult/myid;
MPI_Reduce(&localresult, &final, 1, MPI_INT, MPI_SUM, 1,
MPI_COMM_WORLD);
}
if( final )
{
tag = myid;
MPI_Send(&final, 1, MPI_INT, 0, tag, MPI_COMM_WORLD);
}
if(myid == 0)
MPI_Recv(&final, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG,
MPI_COMM_WORLD, &status);
if(myid == 0)
printf("The final result is: %d \n", final);
MPI_Finalize();
return (0);
}
_______________________________________________________________________
|
|
0
|
|
|
|
Reply
|
MM
|
5/12/2010 4:19:45 PM |
|
Am 12.05.2010, 18:19 Uhr, schrieb MM <malarsr2001@gmail.com>:
> I am new to MPI program.Please help me to correct the correct the
> code.If there's an error please write your comment why its so.Thanks
> for your help!
> _________________________________________________________________
> #include <stdio.h>
> #include "mpi.h"
>
> #define MAXSIZE 20
>
> main(int argc, char *argv[])
> {
> int myid, numprocs, localresult, result[MAXSIZE];
> int i, tag, final;
> MPI_Status status;
>
> MPI_Init(&argc, &argv);
> MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
> MPI_Comm_rank(MPI_COMM_WORLD, &myid);
>
> if ( numprocs > MAXSIZE )
> {
> if ( myid == 0 )
> printf("The number of processes must be less than %d\n",
> MAXSIZE);
> exit(0);
> }
>
> final = 0;
>
> for ( i = 0; i < numprocs; i++)
> result[i] = i;
>
> MPI_Scatter(result, numprocs, MPI_INT, &localresult, 1, MPI_INT, 0,
^^^^^^^^
This should be "1", because it is the number of elements you send to
_every_ process.
> MPI_COMM_WORLD);
>
> if( myid )
> {
> localresult = localresult/myid;
> MPI_Reduce(&localresult, &final, 1, MPI_INT, MPI_SUM, 1,
> MPI_COMM_WORLD);
> }
The first process (with myid == 0) does not execute MPI_Reduce, but if you
use MPI_COMM_WORLD all processes have to call MPI_Reduce!
Michael
|
|
0
|
|
|
|
Reply
|
Michael
|
5/12/2010 5:03:30 PM
|
|
On May 12, 12:03=A0pm, "Michael Hofmann" <michael.hofm...@s2000.tu-
chemnitz.de> wrote:
> Am 12.05.2010, 18:19 Uhr, schrieb MM <malarsr2...@gmail.com>:
>
>
>
>
>
> > I am new to MPI program.Please help me to correct the correct the
> > code.If there's an error please write your comment why its so.Thanks
> > for your help!
> > _________________________________________________________________
> > #include <stdio.h>
> > #include "mpi.h"
>
> > #define MAXSIZE 20
>
> > main(int argc, char *argv[])
> > {
> > =A0 int myid, numprocs, localresult, result[MAXSIZE];
> > =A0 int i, tag, final;
> > =A0 MPI_Status status;
>
> > =A0 MPI_Init(&argc, &argv);
> > =A0 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
> > =A0 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
>
> > =A0 if ( numprocs > MAXSIZE )
> > =A0 {
> > =A0 =A0 =A0 =A0 if ( myid =3D=3D 0 )
> > =A0 =A0 =A0 =A0 =A0 printf("The number of processes must be less than %=
d\n",
> > MAXSIZE);
> > =A0 =A0 =A0 =A0 exit(0);
> > =A0 }
>
> > =A0 final =3D 0;
>
> > =A0 for ( i =3D 0; i < numprocs; i++)
> > =A0 =A0 =A0 result[i] =3D i;
>
> > =A0 MPI_Scatter(result, numprocs, MPI_INT, &localresult, 1, MPI_INT, 0,
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^^^^^^^^
> This should be "1", because it is the number of elements you send to =A0
> _every_ process.
>
> > MPI_COMM_WORLD);
>
> > =A0 if( myid )
> > =A0 {
> > =A0 =A0 localresult =3D localresult/myid;
> > =A0 =A0 MPI_Reduce(&localresult, &final, 1, MPI_INT, MPI_SUM, 1,
> > MPI_COMM_WORLD);
> > =A0 }
>
> The first process (with myid =3D=3D 0) does not execute MPI_Reduce, but i=
f you =A0
> use MPI_COMM_WORLD all processes have to call MPI_Reduce!
>
> Michael- Hide quoted text -
>
> - Show quoted text -
Thanks for your message.I still didn't understand.I am very new to
this program.Can you please show me the error in detail.Thanks!
|
|
0
|
|
|
|
Reply
|
MM
|
5/13/2010 9:58:49 PM
|
|
|
2 Replies
244 Views
(page loaded in 0.809 seconds)
Similiar Articles: MPI Program help - comp.parallel.mpiMPI Program help - comp.parallel.mpi Help with synchronization in a while loop (MPI_Bcast & MPI_Reduce ... Hi, Hope someone can help with this one: I trying to code a ... Beginner for MPI programming - comp.parallel.mpiHello all, I'm a beginner to MPI Programing in C. Need some help in this regard. I found that, MPI also has datatypes. But not getting why thes... Help with synchronization in a while loop (MPI_Bcast & MPI_Reduce ...Hi, Hope someone can help with this one: I trying to code a loop using MPI (MPICH) that is a variation on the trapezoidal rule. The program is comp... Quicksort code - comp.parallel.mpiHi all, Does anyone have a c++ MPI code for the parallel quicksort algorithm I could have a look at to help me implement a parallel sorting step in my program? I can not make MPI recognizes a dual core - comp.parallel.mpi ...MPI Program help - comp.parallel.mpi I can not make MPI recognizes a dual core - comp.parallel.mpi ... I am writing my first program in MPI. I write the sentences ... Intel Fortran Complier + MPICH 1.2.6 (Beginner Question) - comp ...Beginner for MPI programming - comp.parallel.mpi Question on linking MPI programs ... MPI Program help - comp.parallel.mpi Intel Fortran Complier + MPICH 1.2.6 (Beginner ... MPICH and XP Windows Programs - comp.parallel.mpiMPI Program help - comp.parallel.mpi MPICH and XP Windows Programs - comp.parallel.mpi Is this correct? If not what am I doing wrong? Thanks for any help. ... and XP ... To run MPI program using Sun studio cc option - comp.unix.solaris ...To run MPI program using Sun studio cc option - comp.unix.solaris ..... of OpenMP and MPI (both MPI-1 and ... many browsers support running Java programs - and while ... Using a MPI_RECV and MPI_REDUCE - comp.parallel.mpiInitially, because I couldn't debug my program when I was using a MPI_RECV and MPI_REDUCE, I ... MPI Program help - comp.parallel.mpi... MPI_INT, 0, tag, MPI_COMM_WORLD); } if ... Should I use C++ or Java for Numeric Intensive Calculations - comp ...MPI Program help - comp.parallel.mpi Should I use C++ or Java for Numeric Intensive Calculations - comp ... MPI Program help - comp.parallel.mpi Should I use C++ or Java ... Message Passing Interface - Wikipedia, the free encyclopediaMany MPI-1.2 programs were developed before MPI-2. Portability concerns initially slowed, although wider support has ... Features of the Message Passing Interface. MIT ... Medical Professional Institue (MPI) Healthcare programsIf you would like to learn more about the healthcare training programs or need help choosing the MPI program that is right for you please email us at admissions@mpi.edu or ... 7/20/2012 3:22:55 PM
|