Hello Jay,
On Monday 14 May 2007 20:29, Jayanta Roy wrote:
> In my 4 nodes cluster I want to run two MPI_Reduce on two communicators
> (one using Node1, Node2 and other using Node3, Node4).
> Now to create communicator I used ...
> MPI_Comm MPI_COMM_G1, MPI_COMM_G2;
> MPI_Group g0, g1, g2;
> MPI_Comm_group(MPI_COMM_WORLD,&g0);
> MPI_Group_incl(g0,g_size,&r_array[0],&g1);
> MPI_Group_incl(g0,g_size,&r_array[2],&g2);
> MPI_Comm_create(MPI_COMM_WORLD,g1,&MPI_COMM_G1);
> MPI_Comm_create(MPI_COMM_WORLD,g2,&MPI_COMM_G2);
>
> And then I used
>
> f(myrank = 0 || myrank == 1)
If You really are doing above, then no one would participate in this 
operation, but

> MPI_Reduce(corrbuf,corr_sum,CORR_SIZE,MPI_FLOAT,MPI_SUM,0,MPI_COMM_G1);
> if(myrank = 2 || myrank == 3)
            ^^^
every one would particpate here (as myrank=2 != 0)
And then the reduce with processes not belonging to it would fail.


> MPI_Reduce(corrbuf,corr_sum,CORR_SIZE,MPI_FLOAT,MPI_SUM,0,MPI_COMM_G2);
>
> But the program terminate because of "An error occurred in MPI_Reduce"!
>
> Can anybody help me, what is the wrong I am doing?

Just to make sure, the below runs fine.
Please always compile with -Wall or similar compiler-flags.

With best regards,
Rainer
-- 
----------------------------------------------------------------
Dipl.-Inf. Rainer Keller       http://www.hlrs.de/people/keller
 High Performance Computing       Tel: ++49 (0)711-685 6 5858
   Center Stuttgart (HLRS)           Fax: ++49 (0)711-685 6 5832
 POSTAL:Nobelstrasse 19                 email: kel...@hlrs.de     
 ACTUAL:Allmandring 30, R.O.030            AIM:rusraink
 70550 Stuttgart
#include <stdio.h>

#include "mpi.h"

#define CORR_SIZE 1


int main (int argc, char * argv[])
{
  MPI_Comm MPI_COMM_G1, MPI_COMM_G2;
  MPI_Group g0, g1, g2;
  int r_array[4] = {0, 1, 2, 3};
  int size;
  int myrank;
  const int g_size = 2;
  float corrbuf[CORR_SIZE];
  float corrsum[CORR_SIZE];

  MPI_Init (&argc, &argv);

  MPI_Comm_size (MPI_COMM_WORLD, &size);
  MPI_Comm_size (MPI_COMM_WORLD, &myrank);

  if (size != 4)
    {
      fprintf (stderr, "Programm must be run with 4 processes\n");
      return -1;
    }

  MPI_Comm_group (MPI_COMM_WORLD, &g0);
  MPI_Group_incl (g0, g_size, &r_array[0], &g1);
  MPI_Group_incl (g0, g_size, &r_array[2], &g2);
  MPI_Comm_create (MPI_COMM_WORLD, g1, &MPI_COMM_G1);
  MPI_Comm_create (MPI_COMM_WORLD, g2, &MPI_COMM_G2);

  if (myrank == 0 || myrank == 1)
    MPI_Reduce (corrbuf, corrsum, CORR_SIZE, MPI_FLOAT, MPI_SUM, 0, MPI_COMM_G1);

  if (myrank == 2 || myrank == 3)
    MPI_Reduce (corrbuf, corrsum, CORR_SIZE, MPI_FLOAT, MPI_SUM, 0, MPI_COMM_G2);

  MPI_Finalize ();
  return 0;
}

Reply via email to