#!/usr/bin/python
import sys, os, string, re, math

rows = 0
cols =0
layers = 1

if len(sys.argv) == 3:
  rows = int(sys.argv[1])
  cols = int(sys.argv[2])
else:
  if len(sys.argv) == 4:
    rows = int(sys.argv[1])
    cols = int(sys.argv[2])
    layers = int(sys.argv[3])
  else:
    sys.stderr.write("usage : GarnetFileMaker.py <rows> <cols> \n\n")

banks = rows*cols*layers
bank = 0
while bank < banks:
    sys.stdout.write("ext_node:L1Cache:%d int_node:%d link_latency:1 \n" % (bank, bank))
    sys.stdout.write("ext_node:L2Cache:%d int_node:%d link_latency:1 \n" % (bank, bank))
    bank += 1

sys.stdout.write("\n")


col = 0
while col < cols:
    row = 1
    bank = col*rows
    while row < rows:
	sys.stdout.write("int_node:%d int_node:%d link_latency:1 link_weight:1\n" % (bank, bank+1))
	bank += 1
	row += 1
    sys.stdout.write("\n")
    col += 1

sys.stdout.write("\n")

row = 0
while row < rows:
    col = 1
    bank = row
    while col < cols:
        sys.stdout.write("int_node:%d int_node:%d link_latency:1 link_weight:2\n" % (bank, rows+bank))
        bank += rows
        col += 1
    sys.stdout.write("\n")
    row += 1

