コード例 #1
0
ファイル: grid.c プロジェクト: jtfrey/slurm
/* Add a button for a given node. If node_ptr == NULL then fill in any gaps
 * in the grid just for a clean look. Always call with node_ptr == NULL for
 * the last call in the sequence. */
static int _add_button_to_list(node_info_t *node_ptr,
			       button_processor_t *button_processor)
{
	static bool *node_exists = NULL;
	static int node_exists_cnt = 1;
	grid_button_t *grid_button = button_processor->grid_button;
	int *dim_size = NULL, i, coord_x = 0, coord_y = 0;
	int len = 0, len_a = 0;

	if (cluster_dims > 1) {
		dim_size = _get_cluster_dims();
		if (dim_size == NULL) {
			g_error("Could not read dim_size\n");
			return SLURM_ERROR;
		}
		if ((dim_size[0] < 1) || (cluster_dims < 1)) {
			g_error("Invalid dim_size %d or cluster_dims %d\n",
				dim_size[0], cluster_dims);
			return SLURM_ERROR;
		}

		/* Translate a 3D or 4D space into a 2D space to the extent
		 * possible. */
		if (node_exists == NULL) {
			node_exists_cnt = 1;
			for (i = 0; i < cluster_dims; i++)
				node_exists_cnt *= dim_size[i];
			node_exists = xmalloc(sizeof(bool) * node_exists_cnt);
		}
		if (node_ptr) {
			len = strlen(node_ptr->name);
			if (len < cluster_dims) {
				g_error("bad node name %s\n", node_ptr->name);
				return SLURM_ERROR;
			}
			if (cluster_flags & CLUSTER_FLAG_CRAY_A) {
				len_a = strlen(node_ptr->node_addr);
				if (len_a < cluster_dims) {
					g_error("bad node addr %s\n",
						node_ptr->node_addr);
					return SLURM_ERROR;
				}
			}
		}
	}

	if (cluster_dims == 3) {
		int x, y, z;
		if (node_ptr) {
			if (cluster_flags & CLUSTER_FLAG_CRAY_A) {
				x = select_char2coord(
					node_ptr->node_addr[len_a-3]);
				y = select_char2coord(
					node_ptr->node_addr[len_a-2]);
				z = select_char2coord(
					node_ptr->node_addr[len_a-1]);
			} else {
				x = select_char2coord(node_ptr->name[len-3]);
				y = select_char2coord(node_ptr->name[len-2]);
				z = select_char2coord(node_ptr->name[len-1]);
			}
			i = (x * dim_size[1] + y) * dim_size[2] + z;
			node_exists[i] = true;
			_calc_coord_3d(x, y, z,
				       button_processor->default_y_offset,
				       &coord_x, &coord_y, dim_size);
		} else {
			for (x = 0; x < dim_size[0]; x++) {
				for (y = 0; y < dim_size[1]; y++) {
					for (z = 0; z < dim_size[2]; z++) {
						i = (x * dim_size[1] + y) *
							dim_size[2] + z;
						if (node_exists[i])
							continue;
						_calc_coord_3d(x, y, z,
				      			button_processor->
							default_y_offset,
							&coord_x, &coord_y,
							dim_size);
						_build_empty_node(
							coord_x, coord_y,
							button_processor);
					}
				}
			}
			xfree(node_exists);
			return SLURM_SUCCESS;
		}
	}
	if (node_ptr == NULL)
		return SLURM_SUCCESS;

	if (cluster_dims > 1) {
		(*button_processor->coord_x) = coord_x;
		(*button_processor->coord_y) = coord_y;
#if 0
		g_print("%s %d:%d\n", node_ptr->name, coord_x, coord_y);
#endif
	}

	if (!grid_button) {
		grid_button = xmalloc(sizeof(grid_button_t));
		grid_button->color_inx = MAKE_INIT;
		grid_button->inx = (*button_processor->inx);
		grid_button->table = button_processor->table;
		grid_button->table_x = (*button_processor->coord_x);
		grid_button->table_y = (*button_processor->coord_y);
		grid_button->button = gtk_button_new();
		grid_button->node_name = xstrdup(node_ptr->name);

		gtk_widget_set_size_request(grid_button->button,
					    working_sview_config.button_size,
					    working_sview_config.button_size);
		_add_button_signals(grid_button);
		list_append(button_processor->button_list, grid_button);

		gtk_table_attach(button_processor->table, grid_button->button,
				 (*button_processor->coord_x),
				 ((*button_processor->coord_x)+1),
				 (*button_processor->coord_y),
				 ((*button_processor->coord_y)+1),
				 GTK_SHRINK, GTK_SHRINK,
				 1, 1);
	} else {
		grid_button->table_x = (*button_processor->coord_x);
		grid_button->table_y = (*button_processor->coord_y);
		gtk_container_child_set(
			GTK_CONTAINER(button_processor->table),
			grid_button->button,
			"left-attach", (*button_processor->coord_x),
			"right-attach", ((*button_processor->coord_x)+1),
			"top-attach", (*button_processor->coord_y),
			"bottom-attach", ((*button_processor->coord_y)+1),
			NULL);
	}
	/* gtk_container_add(GTK_CONTAINER(grid_button->frame),  */
/* 				  grid_button->button); */
/* 		gtk_frame_set_shadow_type(GTK_FRAME(grid_button->frame), */
/* 					  GTK_SHADOW_ETCHED_OUT); */
	if (cluster_dims < 3) {
		/* On linear systems we just up the x_coord until we hit the
		 * side of the table and then increment the coord_y.  We add
		 * space between each tenth row. */
		(*button_processor->coord_x)++;

		if (button_processor->force_row_break) {
			(*button_processor->coord_x) = 0;
			(*button_processor->coord_y)++;
			gtk_table_set_row_spacing(
				button_processor->table,
				(*button_processor->coord_y)-1,
				working_sview_config.gap_size);
			return SLURM_SUCCESS;
		}

		if ((*button_processor->coord_x)
		    == working_sview_config.grid_x_width) {
			(*button_processor->coord_x) = 0;
			(*button_processor->coord_y)++;
			if (!((*button_processor->coord_y)
			      % working_sview_config.grid_vert))
				gtk_table_set_row_spacing(
					button_processor->table,
					(*button_processor->coord_y)-1,
					working_sview_config.gap_size);
		}

		if ((*button_processor->coord_y) == button_processor->table_y)
			return SLURM_SUCCESS;

		if ((*button_processor->coord_x) &&
		    !((*button_processor->coord_x)
		      % working_sview_config.grid_hori))
			gtk_table_set_col_spacing(
				button_processor->table,
				(*button_processor->coord_x)-1,
				working_sview_config.gap_size);
	}
	return SLURM_SUCCESS;
}
コード例 #2
0
ファイル: grid_functions.c プロジェクト: HPCNow/slurm
/* Build the smap_system_ptr structure from the node records */
extern void init_grid(node_info_msg_t *node_info_ptr, int cols)
{
	int i, j, len;
	int default_y_offset = 0;
	smap_node_t *smap_node;

	smap_system_ptr = xmalloc(sizeof(smap_system_t));

	if (!node_info_ptr) {
		if (params.display != COMMANDS)
			return;
#ifdef HAVE_BG
		uint16_t coords[params.cluster_dims];

		smap_system_ptr->node_cnt = 1;
		for (i=0; i<params.cluster_dims; i++)
			smap_system_ptr->node_cnt *= dim_size[i];
		smap_system_ptr->grid = xmalloc(sizeof(smap_node_t *) *
						smap_system_ptr->node_cnt);
		/* We need to make sure we set up the wires if we
		   don't have a node_info_ptr.
		*/
		bg_configure_ba_setup_wires();

		_internal_setup_grid(0, coords);
#endif
	} else {
		smap_system_ptr->grid = xmalloc(sizeof(smap_node_t *) *
						node_info_ptr->record_count);
		for (i = 0; i < node_info_ptr->record_count; i++) {
			node_info_t *node_ptr = &node_info_ptr->node_array[i];

			if ((node_ptr->name == NULL) ||
			    (node_ptr->name[0] == '\0'))
				continue;

			smap_node = xmalloc(sizeof(smap_node_t));

			len = strlen(node_ptr->name);
			if (params.cluster_dims == 1) {
				smap_node->coord = xmalloc(sizeof(uint16_t));
				j = len - 1;
				while ((node_ptr->name[j] >= '0') &&
				       (node_ptr->name[j] <= '9')) {
					smap_node->coord[0] *= 10;
					smap_node->coord[0] +=
						node_ptr->name[j] - '0';
					j++;
				}
			} else if (params.cluster_flags & CLUSTER_FLAG_CRAY) {
				int len_a, len_h;
				len_a = strlen(node_ptr->node_addr);
				len_h = strlen(node_ptr->node_hostname);
				if (len_a < params.cluster_dims) {
					printf("Invalid node addr %s\n",
					       node_ptr->node_addr);
					xfree(smap_node);
					continue;
				}
				if (len_h < 1) {
					printf("Invalid node hostname %s\n",
					       node_ptr->node_hostname);
					xfree(smap_node);
					continue;
				}
				smap_node->coord = xmalloc(sizeof(uint16_t) *
							   params.cluster_dims);
				len_a -= params.cluster_dims;
				for (j = 0; j < params.cluster_dims; j++) {
					smap_node->coord[j] = select_char2coord(
						node_ptr->node_addr[len_a+j]);
				}
			} else {
				len -= params.cluster_dims;
				if (len < 0) {
					printf("Invalid node name: %s.\n",
					       node_ptr->name);
					xfree(smap_node);
					continue;
				}
				smap_node->coord = xmalloc(sizeof(uint16_t) *
							   params.cluster_dims);
				for (j = 0; j < params.cluster_dims; j++) {
					smap_node->coord[j] = select_char2coord(
						node_ptr->name[len+j]);
				}
			}
			smap_node->index = i;
			smap_node->state = node_ptr->node_state;
			smap_system_ptr->grid[i] = smap_node;
			smap_system_ptr->node_cnt++;
		}
	}

	if (params.cluster_dims == 3) {
		default_y_offset = (dim_size[2] * dim_size[1]) +
				   (dim_size[1] - dim_size[2]);
	} else if (params.cluster_dims == 4) {
		default_y_offset = (dim_size[3] * dim_size[2]) +
				   (dim_size[2] - dim_size[3]);
	}
	if (cols == 0)
		cols = 80;
	for (i = 0; i < smap_system_ptr->node_cnt; i++) {
		smap_node = smap_system_ptr->grid[i];
		if (!smap_node)		/* Null node name */
			continue;
		if (params.cluster_dims == 1) {
			smap_node->grid_xcord = (i % cols) + 1;
			smap_node->grid_ycord = (i / cols) + 1;
		} else if (params.cluster_dims == 2) {
			smap_node->grid_xcord = smap_node->coord[0] + 1;
			smap_node->grid_ycord =
				dim_size[1] - smap_node->coord[1];
		} else if (params.cluster_dims == 3) {
			_calc_coord_3d(smap_node->coord[0], smap_node->coord[1],
				       smap_node->coord[2],
				       default_y_offset,
				       &smap_node->grid_xcord,
				       &smap_node->grid_ycord, dim_size);
		} else if (params.cluster_dims == 4) {
			_calc_coord_4d(smap_node->coord[0], smap_node->coord[1],
				       smap_node->coord[2], smap_node->coord[3],
				       default_y_offset,
				       &smap_node->grid_xcord,
				       &smap_node->grid_ycord, dim_size);
		}
	}
}