connections_general.c 3.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2014, Lawrence Livermore National Security, LLC.
// Produced at the Lawrence Livermore National Laboratory.
//
// Written by:
//     Nikhil Jain <nikhil.jain@acm.org>
//     Abhinav Bhatele <bhatele@llnl.gov>
//     Peer-Timo Bremer <ptbremer@llnl.gov>
//
// LLNL-CODE-678961. All rights reserved.
//
// This file is part of Damselfly. For details, see:
// https://github.com/scalability-llnl/damselfly
// Please also read the LICENSE file for our notice and the LGPL.
//////////////////////////////////////////////////////////////////////////////

#include "stdio.h"
#include "stdlib.h"

//Usage ./binary num_groups num_rows num_columns intra_file inter_file

int main(int argc, char **argv) {
  if(argc < 3) {
24
    printf("Correct usage: %s <num_g> <num_rows> <num_cols> <intra_file> <inter_file>", argv[0]);
25 26 27 28
    exit(0);
  }

  int g = atoi(argv[1]);
29 30
  int r = atoi(argv[2]);
  int c = atoi(argv[3]);
31

32 33
  int total_routers = g * r * c; 

34 35
  FILE *intra = fopen(argv[4], "wb");
  FILE *inter = fopen(argv[5], "wb");
36 37 38 39

  int router = 0;
  int green = 0, black = 1;
  int groups = 0;
40
  printf("\n Rows %d Cols %d Groups %d ", r, c, g);
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
  for(int rows = 0; rows < r; rows++) {
    for(int cols = 0; cols < c; cols++) {
      for(int cols1 = 0; cols1 < c; cols1++) {
        if(cols1 != cols) {
          int dest = (rows * c) + cols1;
          fwrite(&router, sizeof(int), 1, intra);
          fwrite(&dest, sizeof(int), 1, intra);
          fwrite(&green, sizeof(int), 1, intra);
          // printf("INTRA %d %d %d\n", router, dest, green);
        }
      }
      for(int rows1 = 0; rows1 < r; rows1++) {
        if(rows1 != rows) {
          int dest = (rows1 * c) + cols;
          for(int link = 0; link < 3; link++) {
            fwrite(&router, sizeof(int), 1, intra);
            fwrite(&dest, sizeof(int), 1, intra);
            fwrite(&black, sizeof(int), 1, intra);
            // printf("INTRA %d %d %d\n", router, dest, black);
          }
        }
      }
      router++;
    }
  }

  for(int srcg = 0; srcg < g; srcg++) {
    for(int dstg = 0; dstg < g; dstg++) {
      if(srcg != dstg) {
        int nsrcg = srcg;
        int ndstg = dstg;
        if(srcg > dstg) {
          nsrcg--;
        } else {
          ndstg--;
        }
77
        int gsize = 2, gs = c;
78 79 80 81 82 83 84
        for(int row = 0; row < r; row++) {
          int srcrB = srcg * r * c + row * c, srcr;
          int dstrB = dstg * r * c + row * c, dstr;
          int srcB = (ndstg % (gs/2)) * 2;
          int dstB = (nsrcg % (gs/2)) * 2;
          srcr = srcrB + srcB;
          dstr = dstrB + dstB;
85 86 87 88 89 90 91 92

          if(srcr >= total_routers || dstr >= total_routers)
              printf("\n connection between invalid routers src %d and dest %d ", srcr, dstr);

            for(int r = 0; r < 2; r++) {
                for(int block = 0; block < gsize; block++) {
                fwrite(&srcr, sizeof(int), 1, inter);
                fwrite(&dstr, sizeof(int), 1, inter);
93
                printf("INTER %d %d srcg %d destg %d srcrb %d dstrB %d \n", srcr, dstr, srcg, dstg, srcrB, dstrB);
94 95 96
            }
            srcr++;
            dstr++;
97
            }
98 99 100 101 102 103 104 105
        }
      }
    }
  }

  fclose(intra);
  fclose(inter);
}