root/orte/test/system/radix.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. down_search
  2. main

   1 /* -*- C -*-
   2  *
   3  * $HEADER$
   4  *
   5  * The most basic of MPI applications
   6  */
   7 
   8 #include "orte_config.h"
   9 
  10 #include <stdio.h>
  11 #include <unistd.h>
  12 
  13 
  14 
  15 #include "opal/class/opal_list.h"
  16 #include "opal/class/opal_bitmap.h"
  17 
  18 #include "orte/util/proc_info.h"
  19 #include "orte/mca/routed/base/base.h"
  20 #include "orte/runtime/runtime.h"
  21 
  22 static int Radix;
  23 
  24 int down_search(int me, int num_procs,
  25                 int *num_children, opal_list_t *children, opal_bitmap_t *relatives)
  26 {
  27     int i, peer, Sum, NInLevel, rc;
  28     orte_routed_tree_t *child;
  29     opal_bitmap_t *relations;
  30 
  31     /* compute how many procs are at my level */
  32     Sum=1;
  33     NInLevel=1;
  34 
  35     while ( Sum < (me+1) ) {
  36         NInLevel *= Radix;
  37         Sum += NInLevel;
  38     }
  39    /* printf("\trank %d inlevel %d\n", me, NInLevel); */
  40 
  41     /* our children start at our rank + num_in_level */
  42     peer = me + NInLevel;
  43     for (i = 0; i < Radix; i++) {
  44         if (peer < num_procs) {
  45             child = OBJ_NEW(orte_routed_tree_t);
  46             child->vpid = peer;
  47             if (NULL != children) {
  48                /* printf("\t\tadding child rank %d\n", peer); */
  49                 /* this is a direct child - add it to my list */
  50                 opal_list_append(children, &child->super);
  51                 (*num_children)++;
  52                 /* setup the relatives bitmap */
  53                 opal_bitmap_init(&child->relatives, num_procs);
  54                 /* point to the relatives */
  55                 relations = &child->relatives;
  56             } else {
  57               /*  printf("\t\tsetting bit for rank %d\n", peer); */
  58                 /* we are recording someone's relatives - set the bit */
  59                 if (OPAL_SUCCESS != (rc = opal_bitmap_set_bit(relatives, peer))) {
  60                     printf("\t\t\tbit not set!\n");
  61                 }
  62                 /* point to this relations */
  63                 relations = relatives;
  64             }
  65             /* printf("\tdownsearching peer %d\n", peer); */
  66             /* search for this child's relatives */
  67             down_search(peer, num_procs, NULL, NULL, relations);
  68         }
  69         peer += NInLevel;
  70     }
  71 }
  72 
  73 int main(int argc, char **argv)
  74 {
  75     opal_list_t children;
  76     opal_list_item_t *item;
  77     int num_children;
  78     orte_routed_tree_t *child;
  79     int j;
  80     int NProcs;
  81     int Level,Sum,NInLevel,Ii;
  82     int Parent,NInPrevLevel;
  83 
  84 
  85     if (3 != argc) {
  86         printf("usage: radix r x, where r=radix and x=number of procs\n");
  87         exit(1);
  88     }
  89 
  90     orte_init(&argc, &argv, ORTE_PROC_NON_MPI);
  91 
  92     Radix = atoi(argv[1]);
  93     NProcs = atoi(argv[2]);
  94 
  95     for(Ii = 0 ; Ii < NProcs ; Ii++) {
  96         OBJ_CONSTRUCT(&children, opal_list_t);
  97         num_children = 0;
  98         Level=0;
  99         Sum=1;
 100         NInLevel=1;
 101 
 102         while ( Sum < (Ii+1) ) {
 103             Level++;
 104             NInLevel*=Radix;
 105             Sum+=NInLevel;
 106         }
 107         Sum-=NInLevel;
 108 
 109         NInPrevLevel=NInLevel/Radix;
 110 
 111         if( 0 == Ii ) {
 112             Parent=-1;
 113         }  else {
 114             Parent=(Ii-Sum) % NInPrevLevel;
 115             Parent+=(Sum - NInPrevLevel);
 116         }
 117 
 118         fprintf(stderr," I am %d: Parent %d\n",
 119                 Ii,Parent);
 120 
 121     /* compute children and relatives */
 122       down_search(Ii, NProcs, &num_children, &children, NULL);
 123         while (NULL != (item = opal_list_remove_first(&children))) {
 124             child = (orte_routed_tree_t*)item;
 125             fprintf(stderr, "\tchild %d\n", child->vpid);
 126             for (j=0; j < NProcs; j++) {
 127                 if (opal_bitmap_is_set_bit(&child->relatives, j)) {
 128                     fprintf(stderr, "\t\trelation %d\n", j);
 129                 }
 130             }
 131             OBJ_RELEASE(item);
 132         }
 133         OBJ_DESTRUCT(&children);
 134     }
 135 
 136     orte_finalize();
 137 }

/* [<][>][^][v][top][bottom][index][help] */