c - trying to split comm world to multiple comm worlds or blocks in MPI? -


what trying divide group of 8 processors 4 sub groups , hence 4 sub communicators processors in each communicator have id 0 , 1. here output get

rank = 0 newrank = 0

rank = 2 newrank = 0

rank = 6 newrank = 0

rank = 4 newrank = -32766

rank = 7 newrank = 1

rank = 5 newrank = -32766

rank = 3 newrank = 1

rank = 1 newrank = 1

the expected output is

rank = 0 newrank = 0

rank = 2 newrank = 0

rank = 6 newrank = 0

rank = 4 newrank = 0

rank = 7 newrank = 1

rank = 5 newrank = 1

rank = 3 newrank = 1

rank = 1 newrank = 1

as can see getting expected result unable determine causing negative value. seems printing uninitialized variable or data wasn't set there. appreciated?

    #include "mpi.h"     #include <stdio.h>     #include <stdlib.h>      int nprocs = 8; //trying on 8 processors      main(int argc, char *argv[])  {       int rank, new_rank, numtasks;      mpi_group  orig_group, new_group;     mpi_comm   new_comm;      mpi_init(&argc,&argv);     mpi_comm_rank(mpi_comm_world, &rank);     mpi_comm_size(mpi_comm_world, &numtasks);      /* extract original group handle */     mpi_comm_group(mpi_comm_world, &orig_group);       int i;  //need 2 iterations split blocks 8 sub blocks... //first iteration ranks assignment   0 1 2 3   0 1 2 3 //second iteration ranks assignment  0 1  0 1  0 1  0 1      for(i=0; i<2; i++){             /* divide tasks 2 distinct groups based upon rank */         if (rank < nprocs/2) {              int j;              int ranks[8] = {0};                  //list of ranks sub group                 for(j=0;j<nprocs/2;j++){                 ranks[j] = j;             }                mpi_group_incl(orig_group, nprocs/2, ranks, &new_group);          }         else {              int j;              int ranks[8] = {0};                  //list of ranks sub group             for(j=nprocs/2;j<nprocs;j++){                 ranks[j-nprocs/2] = j;             }               mpi_group_incl(orig_group, nprocs/2, ranks, &new_group);         }           /* create new new communicator , perform collective communications */         mpi_comm_create(mpi_comm_world, new_group, &new_comm);           mpi_group_rank (new_group, &new_rank);          //here assign new_group identifier orig_group in next iteration         //mpi_group_incl(orig_group, nprocs/2 ... can use new_group orig_group         orig_group = new_group;         nprocs = nprocs / 2;   // divides nprocs half         rank = new_rank;      }       printf("rank= %d newrank= %d \n",rank,new_rank);      mpi_finalize();       } 

at second iteration, processes initial ranks 0 , 1 fall first branch of if (which ok), all other processes go else branch (which not).

so, processes initial ranks 0 , 1 group successfully; processes initial ranks 2, 3, 6, 7 have group ranks 2 , 3 , group @ second iteration; processes initial ranks 4 , 5 have @ second iteration group ranks 0 , 1 , not included group. hence negative ranks.

your code work if use new_rank instead of rank inside loop (assigning new_rank = rank; before loop).

although advise more straightforward creating of groups: calculate bounds , create groups (unless need hierarchical group structure).


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -