From 2808bbd5c0bc6766a8bb7d4a1c11228671e762e1 Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Sat, 6 Nov 2004 00:35:17 +0000
Subject: [PATCH] dynamic External wiring working on Partition allocator.

---
 src/partition_allocator/graph_solver.c        | 162 +++++++++---------
 src/partition_allocator/graph_solver.h        |   1 +
 src/partition_allocator/graph_structs.c       |  17 +-
 src/partition_allocator/graph_structs.h       |  12 +-
 src/partition_allocator/partition_allocator.c | 139 ++++++++++++++-
 src/partition_allocator/partition_allocator.h |  32 +++-
 6 files changed, 258 insertions(+), 105 deletions(-)

diff --git a/src/partition_allocator/graph_solver.c b/src/partition_allocator/graph_solver.c
index 7ac6e30352e..148d0e08a2b 100644
--- a/src/partition_allocator/graph_solver.c
+++ b/src/partition_allocator/graph_solver.c
@@ -174,8 +174,8 @@ int gs_init(List port_config_list, int num_nodes)
 	while ((switch_config = (switch_config_t*) list_next(itr))){
 		new_connection(&conn);
 		conn->place = EXTERNAL;
-		switch_src = get_switch(switch_config->node_src, switch_config->dim);
-		switch_tar = get_switch(switch_config->node_tar, switch_config->dim);
+/* 		switch_src = get_switch(switch_config->node_src, switch_config->dim); */
+/* 		switch_tar = get_switch(switch_config->node_tar, switch_config->dim); */
 
 		if (!switch_src || ! switch_tar){
 			printf("Error, external switch configuration failed\n");
@@ -1460,58 +1460,59 @@ int _get_connection_partition(connection_t* conn, List partition_list)
 void create_config_9_2d(List configs)
 {
 	switch_config_t* conf;
-	
+	conf = (switch_config_t*) xmalloc(sizeof(switch_config_t));
+
 	/** 
 	 * remember that connections are bidirectional, so we only
 	 * have a connection between nodes once
 	 */
 	/* first X row */
-	new_switch_config(&conf, NO_VAL, X, 0, 3, 1, 4);
+	new_switch_config(conf, NO_VAL, X, 0, 3, 1, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 0, 4, 2, 3);
+	new_switch_config(conf, NO_VAL, X, 0, 4, 2, 3);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 1, 3, 2, 4);
+	new_switch_config(conf, NO_VAL, X, 1, 3, 2, 4);
 	list_append(configs, conf);
 
 	/* second X row */
-	new_switch_config(&conf, NO_VAL, X, 3, 3, 4, 4);
+	new_switch_config(conf, NO_VAL, X, 3, 3, 4, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 3, 4, 5, 3);
+	new_switch_config(conf, NO_VAL, X, 3, 4, 5, 3);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 4, 3, 5, 4);
+	new_switch_config(conf, NO_VAL, X, 4, 3, 5, 4);
 	list_append(configs, conf);
 
 	/* third X row */
-	new_switch_config(&conf, NO_VAL, X, 6, 3, 7, 4);
+	new_switch_config(conf, NO_VAL, X, 6, 3, 7, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 6, 4, 8, 3);
+	new_switch_config(conf, NO_VAL, X, 6, 4, 8, 3);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 7, 3, 8, 4);
+	new_switch_config(conf, NO_VAL, X, 7, 3, 8, 4);
 	list_append(configs, conf);
 
 	/* first Y column */
 
-	new_switch_config(&conf, NO_VAL, Y, 0, 3, 3, 4);
+	new_switch_config(conf, NO_VAL, Y, 0, 3, 3, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Y, 0, 4, 6, 3);
+	new_switch_config(conf, NO_VAL, Y, 0, 4, 6, 3);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Y, 3, 3, 6, 4);
+	new_switch_config(conf, NO_VAL, Y, 3, 3, 6, 4);
 	list_append(configs, conf);
 
 	/* second Y column */
-	new_switch_config(&conf, NO_VAL, Y, 1, 3, 4, 4);
+	new_switch_config(conf, NO_VAL, Y, 1, 3, 4, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Y, 1, 4, 7, 3);
+	new_switch_config(conf, NO_VAL, Y, 1, 4, 7, 3);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Y, 4, 3, 7, 4);
+	new_switch_config(conf, NO_VAL, Y, 4, 3, 7, 4);
 	list_append(configs, conf);
 
 	/* third Y column */
-	new_switch_config(&conf, NO_VAL, Y, 2, 3, 5, 4);
+	new_switch_config(conf, NO_VAL, Y, 2, 3, 5, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Y, 2, 4, 8, 3);
+	new_switch_config(conf, NO_VAL, Y, 2, 4, 8, 3);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Y, 5, 3, 8, 4);
+	new_switch_config(conf, NO_VAL, Y, 5, 3, 8, 4);
 	list_append(configs, conf);
 }
 
@@ -1519,13 +1520,14 @@ void create_config_9_2d(List configs)
 void create_config_3_1d(List configs)
 {
 	switch_config_t* conf;
+	conf = (switch_config_t*) xmalloc(sizeof(switch_config_t));
 
 	/* first X row */
-	new_switch_config(&conf, NO_VAL, X, 0, 3, 1, 4);
+	new_switch_config(conf, NO_VAL, X, 0, 3, 1, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 0, 4, 2, 3);
+	new_switch_config(conf, NO_VAL, X, 0, 4, 2, 3);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 1, 3, 2, 4);
+	new_switch_config(conf, NO_VAL, X, 1, 3, 2, 4);
 	list_append(configs, conf);
 
 }
@@ -1534,34 +1536,35 @@ void create_config_3_1d(List configs)
 void create_config_4_2d(List configs)
 {
 	switch_config_t* conf;
-	
+	conf = (switch_config_t*) xmalloc(sizeof(switch_config_t));
+
 	/** 
 	 * remember that connections are bidirectional, so we only
 	 * have a connection between nodes once
 	 */
 	/* first X row */
-	new_switch_config(&conf, NO_VAL, X, 0, 3, 1, 4);
+	new_switch_config(conf, NO_VAL, X, 0, 3, 1, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 0, 4, 1, 3);
+	new_switch_config(conf, NO_VAL, X, 0, 4, 1, 3);
 	list_append(configs, conf);
 
 	/* second X row */
-	new_switch_config(&conf, NO_VAL, X, 2, 3, 3, 4);
+	new_switch_config(conf, NO_VAL, X, 2, 3, 3, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 2, 4, 3, 3);
+	new_switch_config(conf, NO_VAL, X, 2, 4, 3, 3);
 	list_append(configs, conf);
 
 
 	/* first Y column */
-	new_switch_config(&conf, NO_VAL, Y, 0, 3, 2, 4);
+	new_switch_config(conf, NO_VAL, Y, 0, 3, 2, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Y, 0, 4, 2, 3);
+	new_switch_config(conf, NO_VAL, Y, 0, 4, 2, 3);
 	list_append(configs, conf);
 
 	/* second Y column */
-	new_switch_config(&conf, NO_VAL, Y, 1, 3, 3, 4);
+	new_switch_config(conf, NO_VAL, Y, 1, 3, 3, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Y, 1, 4, 3, 3);
+	new_switch_config(conf, NO_VAL, Y, 1, 4, 3, 3);
 	list_append(configs, conf);
 }
 
@@ -1569,19 +1572,20 @@ void create_config_4_2d(List configs)
 void create_config_4_1d(List configs)
 {
 	switch_config_t* conf;
-	
+	conf = (switch_config_t*) xmalloc(sizeof(switch_config_t));
+
 	/** 
 	 * remember that connections are bidirectional, so we only
 	 * have a connection between nodes once
 	 */
 	/* first X row */
-	new_switch_config(&conf, NO_VAL, X, 0, 3, 1, 4);
+	new_switch_config(conf, NO_VAL, X, 0, 3, 1, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 1, 3, 2, 4);
+	new_switch_config(conf, NO_VAL, X, 1, 3, 2, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 2, 3, 3, 4);
+	new_switch_config(conf, NO_VAL, X, 2, 3, 3, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 3, 3, 0, 4);
+	new_switch_config(conf, NO_VAL, X, 3, 3, 0, 4);
 	list_append(configs, conf);
 }
 
@@ -1589,49 +1593,50 @@ void create_config_4_1d(List configs)
 void create_config_8_1d(List configs)
 {
 	switch_config_t* conf;
-	
+	conf = (switch_config_t*) xmalloc(sizeof(switch_config_t));
+
 	/** 
 	 * remember that connections are bidirectional, so we only
 	 * have one connection between nodes
 	 */
 	/* top row, horizontal connections */
-	new_switch_config(&conf, NO_VAL, X, 0, 3, 2, 4);
+	new_switch_config(conf, NO_VAL, X, 0, 3, 2, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 2, 3, 4, 4);
+	new_switch_config(conf, NO_VAL, X, 2, 3, 4, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 4, 3, 6, 4);
+	new_switch_config(conf, NO_VAL, X, 4, 3, 6, 4);
 	list_append(configs, conf);
 
 	/* bottom row, horizontal connections */
-	new_switch_config(&conf, NO_VAL, X, 1, 4, 3, 3);
+	new_switch_config(conf, NO_VAL, X, 1, 4, 3, 3);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 3, 4, 5, 3);
+	new_switch_config(conf, NO_VAL, X, 3, 4, 5, 3);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 5, 4, 7, 3);
+	new_switch_config(conf, NO_VAL, X, 5, 4, 7, 3);
 	list_append(configs, conf);
 
 	/* 1st column, vertical connections */
-	new_switch_config(&conf, NO_VAL, X, 0, 2, 1, 5);
+	new_switch_config(conf, NO_VAL, X, 0, 2, 1, 5);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 1, 3, 0, 4);
+	new_switch_config(conf, NO_VAL, X, 1, 3, 0, 4);
 	list_append(configs, conf);
 
 	/* 2nd column, vertical connections */
-	new_switch_config(&conf, NO_VAL, X, 2, 2, 3, 5);
+	new_switch_config(conf, NO_VAL, X, 2, 2, 3, 5);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 3, 2, 2, 5);
+	new_switch_config(conf, NO_VAL, X, 3, 2, 2, 5);
 	list_append(configs, conf);
 
 	/* 3rd column, vertical connections */
-	new_switch_config(&conf, NO_VAL, X, 4, 2, 5, 5);
+	new_switch_config(conf, NO_VAL, X, 4, 2, 5, 5);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 5, 2, 4, 5);
+	new_switch_config(conf, NO_VAL, X, 5, 2, 4, 5);
 	list_append(configs, conf);
 
 	/* 4th column, vertical connections */
-	new_switch_config(&conf, NO_VAL, X, 6, 3, 7, 4);
+	new_switch_config(conf, NO_VAL, X, 6, 3, 7, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 7, 2, 6, 5);
+	new_switch_config(conf, NO_VAL, X, 7, 2, 6, 5);
 	list_append(configs, conf);
 }
 
@@ -1640,84 +1645,85 @@ void create_config_8_1d(List configs)
 void create_config_8_3d(List configs)
 {
 	switch_config_t* conf;
-	
+	conf = (switch_config_t*) xmalloc(sizeof(switch_config_t));
+
 	/** 
 	 * remember that connections are bidirectional, so we only
 	 * have a connection between nodes once
 	 */
 	/****************************************/
 	/* first X row Z0 */
-	new_switch_config(&conf, NO_VAL, X, 0, 3, 1, 4);
+	new_switch_config(conf, NO_VAL, X, 0, 3, 1, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 0, 4, 1, 3);
+	new_switch_config(conf, NO_VAL, X, 0, 4, 1, 3);
 	list_append(configs, conf);
 
 	/* second X row Z0*/
-	new_switch_config(&conf, NO_VAL, X, 2, 3, 3, 4);
+	new_switch_config(conf, NO_VAL, X, 2, 3, 3, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 2, 4, 3, 3);
+	new_switch_config(conf, NO_VAL, X, 2, 4, 3, 3);
 	list_append(configs, conf);
 
 
 	/* first X row Z1 */
-	new_switch_config(&conf, NO_VAL, X, 4, 3, 5, 4);
+	new_switch_config(conf, NO_VAL, X, 4, 3, 5, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 4, 4, 5, 3);
+	new_switch_config(conf, NO_VAL, X, 4, 4, 5, 3);
 	list_append(configs, conf);
 
 	/* second X row Z1 */
-	new_switch_config(&conf, NO_VAL, X, 6, 3, 7, 4);
+	new_switch_config(conf, NO_VAL, X, 6, 3, 7, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, X, 6, 4, 7, 3);
+	new_switch_config(conf, NO_VAL, X, 6, 4, 7, 3);
 	list_append(configs, conf);
 
 	/****************************************/
 	/* first Y column Z0 */
-	new_switch_config(&conf, NO_VAL, Y, 0, 3, 2, 4);
+	new_switch_config(conf, NO_VAL, Y, 0, 3, 2, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Y, 0, 4, 2, 3);
+	new_switch_config(conf, NO_VAL, Y, 0, 4, 2, 3);
 	list_append(configs, conf);
 
 	/* second Y column Z0 */
-	new_switch_config(&conf, NO_VAL, Y, 1, 3, 3, 4);
+	new_switch_config(conf, NO_VAL, Y, 1, 3, 3, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Y, 1, 4, 3, 3);
+	new_switch_config(conf, NO_VAL, Y, 1, 4, 3, 3);
 	list_append(configs, conf);
 
 	/* first Y column Z1 */
-	new_switch_config(&conf, NO_VAL, Y, 4, 3, 6, 4);
+	new_switch_config(conf, NO_VAL, Y, 4, 3, 6, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Y, 4, 4, 6, 3);
+	new_switch_config(conf, NO_VAL, Y, 4, 4, 6, 3);
 	list_append(configs, conf);
 
 	/* second Y column Z1 */
-	new_switch_config(&conf, NO_VAL, Y, 5, 3, 7, 4);
+	new_switch_config(conf, NO_VAL, Y, 5, 3, 7, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Y, 5, 4, 7, 3);
+	new_switch_config(conf, NO_VAL, Y, 5, 4, 7, 3);
 	list_append(configs, conf);
 
 	/****************************************/
 	/*  */
-	new_switch_config(&conf, NO_VAL, Z, 0, 3, 4, 4);
+	new_switch_config(conf, NO_VAL, Z, 0, 3, 4, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Z, 0, 4, 4, 3);
+	new_switch_config(conf, NO_VAL, Z, 0, 4, 4, 3);
 	list_append(configs, conf);
 
 	/*  */
-	new_switch_config(&conf, NO_VAL, Z, 1, 3, 5, 4);
+	new_switch_config(conf, NO_VAL, Z, 1, 3, 5, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Z, 1, 4, 5, 3);
+	new_switch_config(conf, NO_VAL, Z, 1, 4, 5, 3);
 	list_append(configs, conf);
 
 	/*  */
-	new_switch_config(&conf, NO_VAL, Z, 2, 3, 6, 4);
+	new_switch_config(conf, NO_VAL, Z, 2, 3, 6, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Z, 2, 4, 6, 3);
+	new_switch_config(conf, NO_VAL, Z, 2, 4, 6, 3);
 	list_append(configs, conf);
 
 	/*  */
-	new_switch_config(&conf, NO_VAL, Z, 3, 3, 7, 4);
+	new_switch_config(conf, NO_VAL, Z, 3, 3, 7, 4);
 	list_append(configs, conf);
-	new_switch_config(&conf, NO_VAL, Z, 3, 4, 7, 3);
+	new_switch_config(conf, NO_VAL, Z, 3, 4, 7, 3);
 	list_append(configs, conf);
 }
diff --git a/src/partition_allocator/graph_solver.h b/src/partition_allocator/graph_solver.h
index 69ceed18668..64f5aa374ed 100644
--- a/src/partition_allocator/graph_solver.h
+++ b/src/partition_allocator/graph_solver.h
@@ -116,6 +116,7 @@ void gs_fini();
 /* */
 void sort_node_id(int* node_id, int size);
 
+/* any size */
 /** 3x3x1 */
 void create_config_9_2d(List switch_config_list);
 /** 2x2x2 */
diff --git a/src/partition_allocator/graph_structs.c b/src/partition_allocator/graph_structs.c
index 7b39e0f15b2..08accea684f 100644
--- a/src/partition_allocator/graph_structs.c
+++ b/src/partition_allocator/graph_structs.c
@@ -907,18 +907,17 @@ void delete_gen(void* object)
 	xfree(object);
 }
 
-void new_switch_config(switch_config_t** config, Label id, dimension_t dim, 
+void new_switch_config(switch_config_t* config, Label id, dimension_t dim, 
 		       Label node_src, int port_src, 
 		       Label node_tar, int port_tar)
 {
-	(*config) = (switch_config_t*) xmalloc(sizeof(switch_config_t));
-
-	(*config)->id = id;
-	(*config)->dim = dim;
-	(*config)->node_src = node_src;
-	(*config)->port_src = port_src;
-	(*config)->node_tar = node_tar;
-	(*config)->port_tar = port_tar;
+	
+	config->id = id;
+	config->dim = dim;
+	config->node_src = node_src;
+	config->port_src = port_src;
+	config->node_tar = node_tar;
+	config->port_tar = port_tar;
 }
 
 void delete_switch_config(void* object)
diff --git a/src/partition_allocator/graph_structs.h b/src/partition_allocator/graph_structs.h
index 7388730a0f4..c2e9cce27fa 100644
--- a/src/partition_allocator/graph_structs.h
+++ b/src/partition_allocator/graph_structs.h
@@ -181,15 +181,11 @@ typedef struct switch_config
 
 	/* dimension */
 	dimension_t dim;
-
-	/* node labels */
-	Label node_src; // source
-	Label node_tar; // target
-
-	/* ports */ 
+	int *node_src; // source
+	int *node_tar; // target
 	int port_src;
 	int port_tar;
-	
+
 } switch_config_t;
 
 /** 
@@ -286,7 +282,7 @@ void delete_gen(void* object);
 char* convert_dim(dimension_t dim);
 
 /**  */
-void new_switch_config(switch_config_t** config, Label id, dimension_t dim, 
+void new_switch_config(switch_config_t* config, Label id, dimension_t dim, 
 	       Label node_src, int port_src, 
 	       Label node_tar, int port_tar);
 /** */
diff --git a/src/partition_allocator/partition_allocator.c b/src/partition_allocator/partition_allocator.c
index b125410d8ba..b8f1eb2f79b 100644
--- a/src/partition_allocator/partition_allocator.c
+++ b/src/partition_allocator/partition_allocator.c
@@ -499,14 +499,14 @@ int _get_part_config(int num_nodes, List switch_config_list, List config_result_
 	/* first we find the partition configurations for the separate
 	 * dimensions
 	 */
-	if (find_all_tori(config_result_list)){
-		printf("error finding all tori\n");
-		goto cleanup;
-	}
+	/* if (find_all_tori(config_result_list)){ */
+/* 		printf("error finding all tori\n"); */
+/* 		goto cleanup; */
+/* 	} */
 	rc = 0;
 
  cleanup:
-	gs_fini();
+	//gs_fini();
 	return rc;
 }
 
@@ -1408,7 +1408,7 @@ void print_pa_request(pa_request_t* pa_request)
 void pa_init()
 {
 	int i;
-	
+	List switch_config_list;
 #ifdef DEBUG_PA
 	printf("pa_init()\n");
 #endif
@@ -1443,6 +1443,7 @@ void pa_init()
 /* 		time(&end); */
 /* 		printf("loading file time: %ld\n", (end-start)); */
 /* 	} else { */
+	
 /* 		switch_config_list = list_create(delete_gen); */
 /* 		create_config_8_1d(switch_config_list); */
 /* 		if (_get_part_config(8, switch_config_list, _conf_result_list[X])){ */
@@ -1479,8 +1480,10 @@ void pa_init()
 /* 	} */
 
 	_pa_system_ptr = xmalloc(sizeof(pa_system_t));
-
+		
 	_create_pa_system(_pa_system_ptr, _conf_result_list);
+	_create_config_even(_pa_system_ptr->grid);
+	
 	_pa_system_list = list_create(_delete_pa_system);
 	_initialized = true;
 	
@@ -1662,6 +1665,112 @@ char* get_conf_result_str(List pa_node_list)
 	return result_str;
 }
 
+/** */
+int _create_config_even(pa_node_t ***grid)
+{
+	int x, y ,z;
+	pa_node_t *source, *target_1, *target_2, *target_first, *target_second;
+	for(x=0;x<DIM_SIZE[X];x++) {
+		for(y=0;y<DIM_SIZE[Y];y++) {
+			for(z=0;z<DIM_SIZE[Z];z++) {
+				source = &grid[x][y][z];
+				
+				if(x<(DIM_SIZE[X]-1))
+					target_1 = &grid[x+1][y][z];
+				else
+					target_1 = NULL;
+				if(x<(DIM_SIZE[X]-2))
+					target_2 = &grid[x+2][y][z];
+				else
+					target_2 = NULL;
+				target_first = &grid[0][y][z];
+				target_second = &grid[1][y][z];
+				_set_up_ports(X, x, source, target_1, target_2, target_first, target_second);
+				
+				if(y<(DIM_SIZE[Y]-1))
+					target_1 = &grid[x][y+1][z];
+				else
+					target_1 = NULL;
+				if(y<(DIM_SIZE[Y]-2))
+					target_2 = &grid[x][y+2][z];
+				else
+					target_2 = NULL;
+				target_first = &grid[x][0][z];
+				target_second = &grid[x][1][z];
+				_set_up_ports(Y, y, source, target_1, target_2, target_first, target_second);
+
+				if(z<(DIM_SIZE[Z]-1))
+					target_1 = &grid[x][y][z+1];
+				else
+					target_1 = NULL;
+				if(z<(DIM_SIZE[Z]-2))
+					target_2 = &grid[x][y][z+2];
+				else
+					target_2 = NULL;
+				target_first = &grid[x][y][0];
+				target_second = &grid[x][y][1];
+				_set_up_ports(Z, z, source, target_1, target_2, target_first, target_second);
+			}
+		}
+	}
+	return 1;
+}
+void _switch_config(pa_node_t* source, pa_node_t* target, int dim, int port_src, int port_tar)
+{
+	pa_switch_t* config = &source->axis_switch[dim];
+	pa_switch_t* config_tar = &target->axis_switch[dim];
+	int i;
+	for(i=0;i<PA_SYSTEM_DIMENSIONS;i++) {
+		config->wire[port_src].node_tar[i] = target->coord[i];
+		config_tar->wire[port_tar].node_tar[i] = source->coord[i];
+	}
+	config->wire[port_src].port_tar = port_tar;
+	config_tar->wire[port_tar].port_tar = port_src;
+}
+
+void _set_up_ports(int dim, int count, pa_node_t* source, pa_node_t* target_1, pa_node_t* target_2, pa_node_t* target_first, pa_node_t* target_second)
+{
+	_switch_config(source, source, dim, 0, 0);
+	_switch_config(source, source, dim, 1, 1);
+	if(count==0) {
+		/* First Node */
+		/* 4->3 of next */
+		_switch_config(source, target_1, dim, 4, 3);
+		/* 2->5 of next */
+		_switch_config(source, target_1, dim, 2, 5);
+		/* 3->4 of next even */
+		_switch_config(source, target_2, dim, 3, 4);
+	} else if(!(count%2)) {
+		if(count<DIM_SIZE[dim]-2) {
+			/* Not Last Even Node */
+			/* 3->4 of next even */
+			_switch_config(source, target_2, dim, 3, 4);
+			/* 2->5 of next */
+			_switch_config(source, target_1, dim, 2, 5);
+			/* 5->2 of next */
+			_switch_config(source, target_1, dim, 5, 2);
+		} else {
+			/* Last Even Node */
+			/* 3->4 of next */
+			_switch_config(source, target_1, dim, 3, 4);
+			/* 5->2 of next */
+			_switch_config(source, target_1, dim, 5, 2);
+			/* 2->5 of first */
+			_switch_config(source, target_first, dim, 2, 5);
+		}
+	} else {
+		if(count<DIM_SIZE[dim]-2) {
+			/* Not Last Odd Node */
+			/* 4->3 of next odd */
+			_switch_config(source, target_2, dim, 4, 3);
+		} else {
+			/* Last Odd Node */
+			/* 5->2 of second */
+			_switch_config(source, target_second, dim, 5, 2);
+		}	
+	}	
+}
+				
 /** */
 int main(int argc, char** argv)
 {
@@ -1682,6 +1791,19 @@ int main(int argc, char** argv)
 	pa_init();
 	time(&end);
 	printf("init: %ld\n", (end-start));
+/* 	int x,y,z,i; */
+/* 	pa_connection_t info; */
+/* 	printf("Wires\n"); */
+/* 	for(x=0;x<1;x++) { */
+/* 		for(y=0;y<DIM_SIZE[Y];y++) { */
+/* 			for(z=0;z<1;z++) { */
+/* 				for(i=0;i<NUM_PORTS_PER_NODE;i++) { */
+/* 					info = _pa_system_ptr->grid[x][y][z].axis_switch[Y].wire[i]; */
+/* 					printf("%d%d%d %d -> %d%d%d %d\n",x,y,z,i,info.node_tar[X],info.node_tar[Y],info.node_tar[Z],info.port_tar); */
+/* 				} */
+/* 			} */
+/* 		} */
+/* 	} */
 	/*
 	  int dead_node1[3] = {0,0,0};
 	  int dead_node2[3] = {1,0,0};
@@ -1750,6 +1872,7 @@ int main(int argc, char** argv)
 	// printf("fini: %ld\n", (end-start));
 
 	delete_pa_request(request);
-
+	gs_fini();
+	
 	return 0;
 }
diff --git a/src/partition_allocator/partition_allocator.h b/src/partition_allocator/partition_allocator.h
index ba0a91e3c7b..1cb321f5b47 100644
--- a/src/partition_allocator/partition_allocator.h
+++ b/src/partition_allocator/partition_allocator.h
@@ -53,6 +53,30 @@ typedef struct {
 	bool force_contig;
 } pa_request_t; 
 
+typedef struct 
+{
+	/* target port */ 
+	int port_tar;
+
+	/* target label */
+	int node_tar[PA_SYSTEM_DIMENSIONS];
+	
+	
+} pa_connection_t;
+/** 
+ * structure that holds the configuration settings for each switch
+ * 
+ * - dimension
+ * - from node, to node
+ * - from port, to port
+ * 
+ */
+typedef struct
+{
+	pa_connection_t wire[NUM_PORTS_PER_NODE];
+
+} pa_switch_t;
+
 /** 
  * pa_node: node within the allocation system.  Note that this node is
  * hard coded for 1d-3d only!  (just have the higher order dims as
@@ -64,12 +88,12 @@ typedef struct {
 
 	/* coordinates */
 	int coord[PA_SYSTEM_DIMENSIONS];
-
+	pa_switch_t axis_switch[PA_SYSTEM_DIMENSIONS];
 	/* shallow copy of the conf_results.  initialized and used as
 	 * array of Lists accessed by dimension, ie conf_result_list[dim]
 	 */
 	List conf_result_list[PA_SYSTEM_DIMENSIONS]; 
-	port_t ports[NUM_PORTS_PER_NODE];
+	
 } pa_node_t;
 
 typedef struct {
@@ -163,4 +187,8 @@ int undo_last_allocatation();
  */
 char* get_conf_result_str(List pa_node_list);
 
+int _create_config_even(pa_node_t ***grid);
+void _switch_config(pa_node_t* source, pa_node_t* target, int dim, int port_src, int port_tar);
+void _set_up_ports(int dim, int count, pa_node_t* source, pa_node_t* target_1, pa_node_t* target_2, pa_node_t* target_first, pa_node_t* target_second);
+
 #endif /* _PARTITION_ALLOCATOR_H_ */
-- 
GitLab