Example #1
0
void		step_game(t_context *gamestate, int key)
{
	WINDOW	*window;
	int		condition;

	if (!gamestate->is_running)
	{
		if (key == KEY_RETURN)
			new_game(gamestate);
	}
	else
	{
		if ((condition = get_input(gamestate, key)) != -1)
		{
			update_grid(gamestate);
			update_score(gamestate);
			if (condition == 1)
			{
				window = gamestate->windows[HIGHSCORES];
				mvwaddstr(window, 8, 2, "U R TEH WINRARZ!!");
				wrefresh(window);
				gamestate->is_running = 0;
				free(gamestate->grid);
			}
		}
	}
}
Example #2
0
void tetris_update() {
	int i;
	for(i = 0; i < MAX_PLAYERS; i++) {
		update_grid(&grids[i]);
		draw_grid(&grids[i]);
	}
}
void GridMapEditor::_configure() {

	if(!node)
		return;

	update_grid();

}
void GridMapEditor::_floor_changed(float p_value) {


	if (updating)
		return;

	edit_floor[edit_axis]=p_value;
	node->set_meta("_editor_floor_",Vector3(edit_floor[0],edit_floor[1],edit_floor[2]));
	update_grid();
	_update_clip();

}
Example #5
0
void update_grid()
{
  int i, j;
  int count = 0;
  recursion_count++;
  for(i=0; i<9; i++)
  {
    for(j=0;j<9;j++)
    {
      if(grid[i][j] == 0)
      {
        count += update_cell(i,j);
      }
    }
  }

  if(count > 0)
    update_grid();

  else
  {
    if(resolved_cells == 81)
    {
      printf("\nSolution:\n");
      display();
    }
    else
    {
      if(eliminate())
        update_grid();
      else
      {
        display();
        printf("\nAfter %d recursive steps cells resolved: %d.\n\n", recursion_count, resolved_cells);
      }
    }
  }
}
Example #6
0
File: tools.cpp Project: dokoto/hwt
	FUNCTION PUBLIC DEFINITION void POST_updateWidgetValues
		(
			const widget* w, 
			const sessionWidgets_t*,
			Buffer_t& buf,
            bool no_events
		)
	{
		Str_t utf8;
		if (w->Type == INPUT || w->Type == INPUT_DATE)
		{			
			update_inputs(w, buf, no_events);
		}
		else if (w->Type == BUTTON)
		{					
			update_buttons(w, buf, no_events);
		}
		else if (w->Type == GRID)
		{
				update_grid(w, buf, no_events);
		}
		else if (w->Type == FILEEXPLORER)
		{
			update_fileexplorer(w, buf, no_events);
		}
		else if (w->Type == LISTBOX)
		{
			update_listbox(w, buf);
		}
		else if (w->Type == CHECKBOXGROUP)
		{
			update_checkboxGroup(w, buf);
		}
		else if (w->Type == TEXTAREA)
		{
			update_textArea(w, buf, no_events);
		}

		if (w->Visible == true)
			buf << utl::Stringf(cjs::set_show, w->Uuid);
		else if (w->Visible == false)
			buf << utl::Stringf(cjs::set_hide, w->Uuid);

		if (w->Disable == true)
			buf << utl::Stringf(cjs::set_disable, w->Uuid);
		else if (w->Disable == false)
			buf << utl::Stringf(cjs::set_enable, w->Uuid);

	}
// realize_main: Called when map_area is realized
// ------------------------------------------- >>
static void realize_main(GtkWidget *widget, gpointer data)
{
	//GdkGLContext *glcontext = gtk_widget_get_gl_context(widget);
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);

	if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
		return;

	vid_width = widget->allocation.width;
	vid_height = widget->allocation.height;
	init_opengl();
	update_map();
	update_grid();

	gdk_gl_drawable_gl_end (gldrawable);
}
Example #8
0
void first_pass()
{
  int i,j,k;
  for(i=0; i<9; i++)
  {
    for(j=0; j<9; j++)
    {
      if(grid[i][j] != 0)
      {
         sub_grid_clear(i,j);
         row_column_clear(i,j);        
      }
    }
  }
  update_grid();
}
// force_map_redraw: Forces the map area to be redrawn
// ------------------------------------------------ >>
void force_map_redraw(bool map, bool grid)
{
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(map_area);

	if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
		return;

	if (grid)
		update_grid();

	if (map)
		update_map();

	gdk_gl_drawable_gl_end(gldrawable);

	gdk_window_invalidate_rect(map_area->window, &map_area->allocation, false);
	update_status_bar();
	//render_map();
}
Example #10
0
int main(int argc, char ** argv) {

	int count;
	struct life_t life;


	init(&life, &argc, &argv);

	for (count = 0; count < life.generations; count++) {

		copy_bounds(&life);

		eval_rules(&life);

		update_grid(&life);
	}
	cleanup(&life);
	exit(EXIT_SUCCESS);
}
Example #11
0
static bool expose_event(RobWidget* handle, cairo_t* cr, cairo_rectangle_t *ev) {
	SFSUI* ui = (SFSUI*)GET_HANDLE(handle);

	if (ui->update_grid) {
		update_grid(ui);
		ui->update_grid = false;
	}
	if (ui->clear_persistence) {
		cairo_t* crx;
		crx = cairo_create (ui->sf_dat);
		rounded_rectangle (crx, SS_BORDER, SS_BORDER, SS_SIZE, SS_SIZE, SS_BORDER);
		cairo_set_source_rgba(crx, 0, 0, 0, 1.0);
		cairo_fill(crx);
		cairo_destroy(crx);
		ui->clear_persistence = false;
	}

	if (pthread_mutex_trylock (&ui->fft_lock) == 0 ) {
		if (robtk_cbtn_get_active(ui->btn_oct)) {
			plot_data_oct(ui);
		} else {
			plot_data_fft(ui);
		}
		pthread_mutex_unlock (&ui->fft_lock);
	}

	cairo_rectangle (cr, ev->x, ev->y, ev->width, ev->height);
	cairo_clip (cr);

	cairo_set_source_surface(cr, ui->sf_ann, 0, 0);
	cairo_paint (cr);

	cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
	cairo_set_source_surface(cr, ui->sf_dat, 0, 0);
	cairo_paint (cr);

	return TRUE;
}
Example #12
0
static void	 do_events(s_game	*game,
			   s_perso	**persos,
			   s_sound	*sounds)
{
  SDL_Event	 event;
  int		 t1 = 0;

  while (1)
    {
      handle_time(game, &t1, 1, persos);

      update_grid(game, persos);

      update_board(game, persos, sounds);
      update_info(game, persos);
      update_items(game, persos);
      SDL_PollEvent(&event);
      input_actions(game, event, persos, sounds);
      SDL_BlitSurface(game->help_s, NULL, game->screen, &game->help_r);
      SDL_Flip(game->screen);
      game->trigger = 0;
    }
}
Example #13
0
/* main drawing callback */
static bool expose_event(RobWidget* handle, cairo_t* cr, cairo_rectangle_t *ev) {
	MF2UI* ui = (MF2UI*)GET_HANDLE(handle);

	if (ui->update_grid) {
		ui->width  = floor(ui->scale * 2 * (PH_RAD + XOFF));
		ui->height = floor(ui->scale * 2 * (PH_RAD + YOFF));

		m0_create_surfaces(ui);
		update_grid(ui);
		ui->update_grid = false;
	}

	cairo_translate(cr,
			rint((ui->m0_width - ui->width) * .5),
			rint((ui->m0_height - ui->height) * .5));

	if (pthread_mutex_trylock (&ui->fft_lock) == 0 ) {
		if (robtk_cbtn_get_active(ui->btn_oct)) {
			plot_data_oct(ui);
		} else {
			plot_data_fft(ui);
		}
		pthread_mutex_unlock (&ui->fft_lock);
	}

	cairo_rectangle (cr, ev->x, ev->y, ev->width, ev->height);
	cairo_clip (cr);

	cairo_set_source_surface(cr, ui->sf_ann, 0, 0);
	cairo_paint (cr);

	cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
	cairo_set_source_surface(cr, ui->sf_dat, 0, 0);
	cairo_paint (cr);

	return TRUE;
}
Example #14
0
int main(int argc, char ** argv) {
	int count;
	struct life_t life;

	init(&life, &argc, &argv);

	while (1) {
		if (life.do_display)
			do_draw(&life);

		copy_bounds(&life);

		eval_rules(&life);

		update_grid(&life);

		throttle(&life);

	}

	cleanup(&life);

	exit(EXIT_SUCCESS);
}
Example #15
0
void GridMapEditor::edit(GridMap *p_gridmap) {

	node=p_gridmap;
	VS *vs = VS::get_singleton();

	last_mouseover=Vector3(-1,-1,-1);
	input_action=INPUT_NONE;
	selection.active=false;
	_update_selection_transform();
	_update_duplicate_indicator();

	spatial_editor  = editor->get_editor_plugin_screen()->cast_to<SpatialEditorPlugin>();

	if (!node) {
		set_process(false);
		for(int i=0;i<3;i++) {
			VisualServer::get_singleton()->instance_geometry_set_flag(grid_instance[i],VS::INSTANCE_FLAG_VISIBLE,false);

		}

		VisualServer::get_singleton()->instance_geometry_set_flag(cursor_instance, VS::INSTANCE_FLAG_VISIBLE,false);

		_clear_areas();

		return;
	}


	update_pallete();
	update_areas();

	set_process(true);

	Vector3 edited_floor = p_gridmap->get_meta("_editor_floor_");
	clip_mode=p_gridmap->has_meta("_editor_clip_")?ClipMode(p_gridmap->get_meta("_editor_clip_").operator int()):CLIP_DISABLED;



	for(int i=0;i<3;i++) {
		if (vs->mesh_get_surface_count(grid[i])>0)
			vs->mesh_remove_surface(grid[i],0);
		edit_floor[i]=edited_floor[i];

	}

	{

		//update grids
		indicator_mat = VisualServer::get_singleton()->fixed_material_create();
		VisualServer::get_singleton()->material_set_flag( indicator_mat, VisualServer::MATERIAL_FLAG_UNSHADED, true );
		VisualServer::get_singleton()->material_set_flag( indicator_mat, VisualServer::MATERIAL_FLAG_ONTOP, false );

		VisualServer::get_singleton()->fixed_material_set_param(indicator_mat,VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE,Color(0.8,0.5,0.1));
		VisualServer::get_singleton()->fixed_material_set_flag( indicator_mat, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA, true );
		VisualServer::get_singleton()->fixed_material_set_flag( indicator_mat, VisualServer::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY, true );


		Vector<Vector3> grid_points[3];
		Vector<Color> grid_colors[3];

		float cell_size[3]={p_gridmap->get_cell_size(),p_gridmap->get_cell_size(),p_gridmap->get_cell_size()};

		for(int i=0;i<3;i++) {

			Vector3 axis;
			axis[i]=1;
			Vector3 axis_n1;
			axis_n1[(i+1)%3]=cell_size[(i+1)%3];
			Vector3 axis_n2;
			axis_n2[(i+2)%3]=cell_size[(i+2)%3];

			for(int j=-GRID_CURSOR_SIZE;j<=GRID_CURSOR_SIZE;j++) {

				for(int k=-GRID_CURSOR_SIZE;k<=GRID_CURSOR_SIZE;k++) {

					Vector3 p = axis_n1*j + axis_n2 *k;
					float trans = Math::pow(MAX(0,1.0-(Vector2(j,k).length()/GRID_CURSOR_SIZE)),2);

					Vector3 pj = axis_n1*(j+1) + axis_n2 *k;
					float transj = Math::pow(MAX(0,1.0-(Vector2(j+1,k).length()/GRID_CURSOR_SIZE)),2);

					Vector3 pk = axis_n1*j + axis_n2 *(k+1);
					float transk = Math::pow(MAX(0,1.0-(Vector2(j,k+1).length()/GRID_CURSOR_SIZE)),2);

					grid_points[i].push_back(p);
					grid_points[i].push_back(pk);
					grid_colors[i].push_back(Color(1,1,1,trans));
					grid_colors[i].push_back(Color(1,1,1,transk));

					grid_points[i].push_back(p);
					grid_points[i].push_back(pj);
					grid_colors[i].push_back(Color(1,1,1,trans));
					grid_colors[i].push_back(Color(1,1,1,transj));
				}

			}

			Array d;
			d.resize(VS::ARRAY_MAX);
			d[VS::ARRAY_VERTEX]=grid_points[i];
			d[VS::ARRAY_COLOR]=grid_colors[i];
			VisualServer::get_singleton()->mesh_add_surface(grid[i],VisualServer::PRIMITIVE_LINES,d);
			VisualServer::get_singleton()->mesh_surface_set_material(grid[i],0,indicator_mat);


		}

	}

	update_grid();
	_update_clip();
	_update_areas_display();


}
Example #16
0
void  GridMapEditor::_menu_option(int p_option) {


	switch(p_option) {

		case MENU_OPTION_CONFIGURE: {


		} break;
		case MENU_OPTION_LOCK_VIEW: {

			int index=options->get_popup()->get_item_index(MENU_OPTION_LOCK_VIEW);
			lock_view=!options->get_popup()->is_item_checked(index);

			options->get_popup()->set_item_checked(index,lock_view);
		} break;
		case MENU_OPTION_CLIP_DISABLED:
		case MENU_OPTION_CLIP_ABOVE:
		case MENU_OPTION_CLIP_BELOW: {

			clip_mode=ClipMode(p_option-MENU_OPTION_CLIP_DISABLED);
			for(int i=0;i<3;i++) {

				int index=options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED+i);
				options->get_popup()->set_item_checked(index,i==clip_mode);

			}

			_update_clip();
		} break;
		case MENU_OPTION_X_AXIS:
		case MENU_OPTION_Y_AXIS:
		case MENU_OPTION_Z_AXIS: {

			int new_axis = p_option-MENU_OPTION_X_AXIS;
			for(int i=0;i<3;i++) {
				int idx=options->get_popup()->get_item_index(MENU_OPTION_X_AXIS+i);
				options->get_popup()->set_item_checked(idx,i==new_axis);
			}
			edit_axis=Vector3::Axis(new_axis);
			update_grid();
			_update_clip();

		} break;
		case MENU_OPTION_CURSOR_ROTATE_Y: {
			Basis r;
			if (input_action==INPUT_DUPLICATE) {

				r.set_orthogonal_index(selection.duplicate_rot);
				r.rotate(Vector3(0,1,0),-Math_PI/2.0);
				selection.duplicate_rot=r.get_orthogonal_index();
				_update_duplicate_indicator();
				break;
			}
			r.set_orthogonal_index(cursor_rot);
			r.rotate(Vector3(0,1,0),-Math_PI/2.0);
			cursor_rot=r.get_orthogonal_index();
			_update_cursor_transform();
		} break;
		case MENU_OPTION_CURSOR_ROTATE_X: {
			Basis r;
			if (input_action==INPUT_DUPLICATE) {

				r.set_orthogonal_index(selection.duplicate_rot);
				r.rotate(Vector3(1,0,0),-Math_PI/2.0);
				selection.duplicate_rot=r.get_orthogonal_index();
				_update_duplicate_indicator();
				break;
			}

			r.set_orthogonal_index(cursor_rot);
			r.rotate(Vector3(1,0,0),-Math_PI/2.0);
			cursor_rot=r.get_orthogonal_index();
			_update_cursor_transform();
		} break;
		case MENU_OPTION_CURSOR_ROTATE_Z: {
			Basis r;
			if (input_action==INPUT_DUPLICATE) {

				r.set_orthogonal_index(selection.duplicate_rot);
				r.rotate(Vector3(0,0,1),-Math_PI/2.0);
				selection.duplicate_rot=r.get_orthogonal_index();
				_update_duplicate_indicator();
				break;
			}

			r.set_orthogonal_index(cursor_rot);
			r.rotate(Vector3(0,0,1),-Math_PI/2.0);
			cursor_rot=r.get_orthogonal_index();
			_update_cursor_transform();
		} break;
		case MENU_OPTION_CURSOR_BACK_ROTATE_Y: {
			Basis r;
			r.set_orthogonal_index(cursor_rot);
			r.rotate(Vector3(0,1,0),Math_PI/2.0);
			cursor_rot=r.get_orthogonal_index();
			_update_cursor_transform();
		} break;
		case MENU_OPTION_CURSOR_BACK_ROTATE_X: {
			Basis r;
			r.set_orthogonal_index(cursor_rot);
			r.rotate(Vector3(1,0,0),Math_PI/2.0);
			cursor_rot=r.get_orthogonal_index();
			_update_cursor_transform();
		} break;
		case MENU_OPTION_CURSOR_BACK_ROTATE_Z: {
			Basis r;
			r.set_orthogonal_index(cursor_rot);
			r.rotate(Vector3(0,0,1),Math_PI/2.0);
			cursor_rot=r.get_orthogonal_index();
			_update_cursor_transform();
		} break;
		case MENU_OPTION_CURSOR_CLEAR_ROTATION: {

			if (input_action==INPUT_DUPLICATE) {


				selection.duplicate_rot=0;
				_update_duplicate_indicator();
				break;
			}

			cursor_rot=0;
			_update_cursor_transform();
		} break;


		case MENU_OPTION_DUPLICATE_SELECTS: {
			int idx = options->get_popup()->get_item_index(MENU_OPTION_DUPLICATE_SELECTS);
			options->get_popup()->set_item_checked( idx, !options->get_popup()->is_item_checked( idx ) );
		} break;
		case MENU_OPTION_SELECTION_MAKE_AREA:
		case MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR: {

			if (!selection.active)
				break;
			int area = node->get_unused_area_id();
			Error err = node->create_area(area,Rect3(selection.begin,selection.end-selection.begin+Vector3(1,1,1)));
			if (err!=OK) {


			}
			if (p_option==MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR) {

				node->area_set_exterior_portal(area,true);
			}
			_update_areas_display();
			update_areas();


		} break;
		case MENU_OPTION_REMOVE_AREA: {
			if (selected_area<1)
				return;
			node->erase_area(selected_area);
			_update_areas_display();
			update_areas();
		} break;
		case MENU_OPTION_SELECTION_DUPLICATE:
			if (!(selection.active && input_action==INPUT_NONE))
				return;
			if (last_mouseover==Vector3(-1,-1,-1)) //nono mouseovering anythin
				break;

			input_action=INPUT_DUPLICATE;
			selection.click=last_mouseover;
			selection.current=last_mouseover;
			selection.duplicate_rot=0;
			_update_duplicate_indicator();
			break;
		case MENU_OPTION_SELECTION_CLEAR: {
			if (!selection.active)
				return;

			_delete_selection();


		} break;
		case MENU_OPTION_GRIDMAP_SETTINGS: {
			settings_dialog->popup_centered(settings_vbc->get_combined_minimum_size() + Size2(50, 50));
		} break;

	}
}
Example #17
0
int main(int argc, char **argv)
{
	log_options_t opts = LOG_OPTS_STDERR_ONLY;
	node_info_msg_t *node_info_ptr = NULL;
	node_info_msg_t *new_node_ptr = NULL;
	int error_code;
	int height = 40;
	int width = 100;
	int startx = 0;
	int starty = 0;
	int end = 0;
	int i;
	int rc;

	slurm_conf_init(NULL);
	log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_DAEMON, NULL);
	parse_command_line(argc, argv);
	if (params.verbose) {
		opts.stderr_level += params.verbose;
		log_alter(opts, SYSLOG_FACILITY_USER, NULL);
	}

	if (params.cluster_dims == 4) {
		min_screen_width = 92;
	} else if (params.cluster_dims == 3)
		min_screen_width = 92;

	/* no need for this if you are resolving */
	while (slurm_load_node((time_t) NULL,
			       &new_node_ptr, SHOW_ALL)) {
		if (params.resolve || (params.display == COMMANDS)) {
			new_node_ptr = NULL;
			break;		/* just continue */
		}
		error_code = slurm_get_errno();
		printf("slurm_load_node: %s\n",
		       slurm_strerror(error_code));
		if (params.iterate == 0)
			exit(1);
		sleep(10);	/* keep trying to reconnect */
	}

	select_g_ba_init(new_node_ptr, 0);

	if (dim_size == NULL) {
		dim_size = get_cluster_dims(new_node_ptr);
		if ((dim_size == NULL) || (dim_size[0] < 1))
			fatal("Invalid system dimensions");
	}
	_init_colors();

	if (params.resolve) {
		char *ret_str = resolve_mp(params.resolve, new_node_ptr);
		if (ret_str) {
			printf("%s", ret_str);
			xfree(ret_str);
		}
		_smap_exit(0);	/* Calls exit(), no return */
	}
	if (!params.commandline) {
		int check_width = min_screen_width;

		initscr();
		init_grid(new_node_ptr, COLS);
		signal(SIGWINCH, (void (*)(int))_resize_handler);

		if (params.cluster_dims == 4) {
			height = dim_size[2] * dim_size[3] + dim_size[2] + 3;
			width = (dim_size[1] + dim_size[3] + 1) * dim_size[0]
				 + 2;
			check_width += width;
		} else if (params.cluster_dims == 3) {
			height = dim_size[1] * dim_size[2] + dim_size[1] + 3;
			width = dim_size[0] + dim_size[2] + 3;
			check_width += width;
		} else {
			height = 10;
			width = COLS;
		}

	        if ((COLS < check_width) || (LINES < height)) {
			endwin();
			error("Screen is too small make sure the screen "
			      "is at least %dx%d\n"
			      "Right now it is %dx%d\n",
			      check_width,
			      height,
			      COLS,
			      LINES);
			_smap_exit(1);	/* Calls exit(), no return */
		}

		raw();
		keypad(stdscr, true);
		noecho();
		cbreak();
		curs_set(0);
		nodelay(stdscr, true);
		start_color();
		_set_pairs();

		grid_win = newwin(height, width, starty, startx);
		max_display = (getmaxy(grid_win) - 1) * (getmaxx(grid_win) - 1);

		if (params.cluster_dims == 4) {
			startx = width;
			width = COLS - width - 2;
			height = LINES;
		} else if (params.cluster_dims == 3) {
			startx = width;
			width = COLS - width - 2;
			height = LINES;
		} else {
			startx = 0;
			starty = height;
			height = LINES - height;
		}

		text_win = newwin(height, width, starty, startx);
        }
	while (!end) {
		if (!params.commandline) {
			_get_option();
redraw:
			clear_window(text_win);
			clear_window(grid_win);
			move(0, 0);

			update_grid(new_node_ptr);
			main_xcord = 1;
			main_ycord = 1;
		}

		if (!params.no_header)
			print_date();

		clear_grid();
		switch (params.display) {
		case JOBS:
			get_job();
			break;
		case RESERVATIONS:
			get_reservation();
			break;
		case SLURMPART:
			get_slurm_part();
			break;
		case COMMANDS:
#ifdef HAVE_BG
			wclear(text_win);
			get_command();
#else
			error("Must be on a real BG SYSTEM to "
			      "run this command");
			if (!params.commandline)
				endwin();
			_smap_exit(1);	/* Calls exit(), no return */
#endif
			break;
		case BGPART:
			if (params.cluster_flags & CLUSTER_FLAG_BG)
				get_bg_part();
			else {
				error("Must be on a BG SYSTEM to "
				      "run this command");
				if (!params.commandline)
					endwin();
				_smap_exit(1);	/* Calls exit(), no return */
			}
			break;
		}

		if (!params.commandline) {
			box(text_win, 0, 0);
			wnoutrefresh(text_win);

			print_grid();
			box(grid_win, 0, 0);
			wnoutrefresh(grid_win);

			doupdate();

			node_info_ptr = new_node_ptr;
			if (node_info_ptr) {
				error_code = slurm_load_node(
					node_info_ptr->last_update,
					&new_node_ptr, SHOW_ALL);
				if (error_code == SLURM_SUCCESS)
					slurm_free_node_info_msg(
						node_info_ptr);
				else if (slurm_get_errno()
					 == SLURM_NO_CHANGE_IN_DATA) {
					error_code = SLURM_SUCCESS;
					new_node_ptr = node_info_ptr;
				}
			} else {
				error_code = slurm_load_node(
					(time_t) NULL,
					&new_node_ptr, SHOW_ALL);
			}
			if (error_code && (quiet_flag != 1)) {
				if (!params.commandline) {
					mvwprintw(
						text_win,
						main_ycord,
						1,
						"slurm_load_node: %s",
						slurm_strerror(
							slurm_get_errno()));
					main_ycord++;
				} else {
					printf("slurm_load_node: %s",
					       slurm_strerror(
						       slurm_get_errno()));
				}
			}
		}

		if (params.iterate) {
			for (i = 0; i < params.iterate; i++) {
				sleep(1);
				if (!params.commandline) {
					if ((rc = _get_option()) == 1)
						goto redraw;
					else if (resize_screen) {
						resize_screen = 0;
						goto redraw;
					}
				}
			}
		} else
			break;

	}

	if (!params.commandline) {
		nodelay(stdscr, false);
		getch();
		endwin();
	}

	_smap_exit(0);	/* Calls exit(), no return */
	exit(0);	/* Redundant, but eliminates compiler warning */
}
Example #18
0
int main(int argc, char **argv)
{
    int r,p;
    int n, energy, niters, px, py;

    int rx, ry;
    int north, south, west, east;
    int bx, by, offx, offy;

    /* three heat sources */
    const int nsources = 3;
    int sources[nsources][2];
    int locnsources;             /* number of sources in my area */
    int locsources[nsources][2]; /* sources local to my rank */

    double t1, t2;

    int iter, i, j;

    double heat, rheat;

    int final_flag;

    /* initialize MPI envrionment */
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &r);
    MPI_Comm_size(MPI_COMM_WORLD, &p);

    /* create shared memory communicator */
    MPI_Comm shmcomm;
    MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &shmcomm);

    int sr, sp; // rank and size in shmem comm
    MPI_Comm_size(shmcomm, &sp);
    MPI_Comm_rank(shmcomm, &sr);

    // this code works only on comm world!
    if(sp != p) MPI_Abort(MPI_COMM_WORLD, 1);

    /* argument checking and setting */
    setup(r, p, argc, argv,
          &n, &energy, &niters, &px, &py, &final_flag);

    if (final_flag == 1) {
        MPI_Finalize();
        exit(0);
    }

    /* determine my coordinates (x,y) -- r=x*a+y in the 2d processor array */
    rx = r % px;
    ry = r / px;

    /* determine my four neighbors */
    north = (ry - 1) * px + rx; if (ry-1 < 0)   north = MPI_PROC_NULL;
    south = (ry + 1) * px + rx; if (ry+1 >= py) south = MPI_PROC_NULL;
    west = ry * px + rx - 1;    if (rx-1 < 0)   west = MPI_PROC_NULL;
    east = ry * px + rx + 1;    if (rx+1 >= px) east = MPI_PROC_NULL;

    /* decompose the domain */
    bx = n / px;    /* block size in x */
    by = n / py;    /* block size in y */
    offx = rx * bx; /* offset in x */
    offy = ry * by; /* offset in y */

    /* printf("%i (%i,%i) - w: %i, e: %i, n: %i, s: %i\n", r, ry,rx,west,east,north,south); */

    int size = (bx+2)*(by+2); /* process-local grid (including halos (thus +2)) */
    double *mem;
    MPI_Win win;
    MPI_Win_allocate_shared(2*size*sizeof(double), 1, MPI_INFO_NULL, shmcomm, &mem, &win);

    double *tmp;
    double *anew=mem; /* each rank's offset */
    double *aold=mem+size; /* second half is aold! */

    double *northptr, *southptr, *eastptr, *westptr;
    double *northptr2, *southptr2, *eastptr2, *westptr2;
    MPI_Aint sz;
    int dsp_unit;
    /* locate the shared memory region for each neighbor */
    MPI_Win_shared_query(win, north, &sz, &dsp_unit, &northptr);
    MPI_Win_shared_query(win, south, &sz, &dsp_unit, &southptr);
    MPI_Win_shared_query(win, east, &sz, &dsp_unit, &eastptr);
    MPI_Win_shared_query(win, west, &sz, &dsp_unit, &westptr);
    northptr2 = northptr+size;
    southptr2 = southptr+size;
    eastptr2 = eastptr+size;
    westptr2 = westptr+size;

    /* initialize three heat sources */
    init_sources(bx, by, offx, offy, n,
                 nsources, sources, &locnsources, locsources);

    t1 = MPI_Wtime(); /* take time */

    MPI_Win_lock_all(0, win);    
    for (iter = 0; iter < niters; ++iter) {
        /* refresh heat sources */
        for (i = 0; i < locnsources; ++i) {
            aold[ind(locsources[i][0],locsources[i][1])] += energy; /* heat source */
        }

	MPI_Win_sync(win);
	MPI_Barrier(shmcomm);

	/* exchange data with neighbors */
	if(north != MPI_PROC_NULL) {
	  for(i=0; i<bx; ++i) aold[ind(i+1,0)] = northptr2[ind(i+1,by)]; /* pack loop - last valid region */
	}
	if(south != MPI_PROC_NULL) {
	  for(i=0; i<bx; ++i) aold[ind(i+1,by+1)] = southptr2[ind(i+1,1)]; /* pack loop */
	}
	if(east != MPI_PROC_NULL) {
	  for(i=0; i<by; ++i) aold[ind(bx+1,i+1)] = eastptr2[ind(1,i+1)]; /* pack loop */
	}
	if(west != MPI_PROC_NULL) {
	  for(i=0; i<by; ++i) aold[ind(0,i+1)] = westptr2[ind(bx,i+1)]; /* pack loop */
	}

        /* update grid points */
        update_grid(bx, by, aold, anew, &heat);

        /* swap working arrays */
        tmp = anew; anew = aold; aold = tmp;

        /* optional - print image */
        if (iter == niters-1) printarr_par(iter, anew, n, px, py, rx, ry, bx, by, offx, offy, shmcomm);
    }

    MPI_Win_unlock_all(win);
    t2 = MPI_Wtime();

    /* get final heat in the system */
    MPI_Allreduce(&heat, &rheat, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
    if (!r) printf("[%i] last heat: %f time: %f\n", r, rheat, t2-t1);

    /* free working arrays and communication buffers */
    MPI_Win_free(&win);
    MPI_Comm_free(&shmcomm);

    MPI_Finalize();
}
int main(int argc, char **argv)
{
    int rank, size;
    int n, energy, niters, px, py;

    int north, south, west, east;
    int bx, by, offx, offy;

    /* three heat sources */
    const int nsources = 3;
    int sources[nsources][2];
    int locnsources;             /* number of sources in my area */
    int locsources[nsources][2]; /* sources local to my rank */

    double t1, t2;

    int iter, i;

    double *aold, *anew, *tmp;

    double heat, rheat;

    int final_flag;

    /* initialize MPI envrionment */
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    /* argument checking and setting */
    setup(rank, size, argc, argv,
          &n, &energy, &niters, &px, &py, &final_flag);

    if (final_flag == 1) {
        MPI_Finalize();
        exit(0);
    }

    /* Create a communicator with a topology */
    MPI_Comm cart_comm;
    int dims[2] = {0,0}, periods[2] = {0,0}, coords[2];
    MPI_Dims_create(size, 2, dims);
    MPI_Cart_create(MPI_COMM_WORLD, 2, dims, periods, 0, &cart_comm);
    MPI_Cart_coords(cart_comm, rank, 2, coords);

    /* determine my four neighbors */
    MPI_Cart_shift(cart_comm, 0, 1, &west, &east);
    MPI_Cart_shift(cart_comm, 1, 1, &north, &south);

    /* decompose the domain */
    bx = n / px;    /* block size in x */
    by = n / py;    /* block size in y */
    offx = coords[0] * bx; /* offset in x */
    offy = coords[1] * by; /* offset in y */

    /* printf("%i (%i,%i) - w: %i, e: %i, n: %i, s: %i\n", rank, ry,rx,west,east,north,south); */

    /* allocate working arrays & communication buffers */
    MPI_Alloc_mem((bx+2)*(by+2)*sizeof(double), MPI_INFO_NULL, &aold); /* 1-wide halo zones! */
    MPI_Alloc_mem((bx+2)*(by+2)*sizeof(double), MPI_INFO_NULL, &anew); /* 1-wide halo zones! */

    /* initialize three heat sources */
    init_sources(bx, by, offx, offy, n,
                 nsources, sources, &locnsources, locsources);

    /* create north-south datatype */
    MPI_Datatype north_south_type;
    MPI_Type_contiguous(bx, MPI_DOUBLE, &north_south_type);
    MPI_Type_commit(&north_south_type);

    /* create east-west type */
    MPI_Datatype east_west_type;
    MPI_Type_vector(by,1,by+2,MPI_DOUBLE, &east_west_type);
    MPI_Type_commit(&east_west_type);

    t1 = MPI_Wtime(); /* take time */

    for (iter = 0; iter < niters; ++iter) {

        /* refresh heat sources */
        for (i = 0; i < locnsources; ++i) {
            aold[ind(locsources[i][0],locsources[i][1])] += energy; /* heat source */
        }

        /* exchange data with neighbors */
        int counts[4] = {1, 1, 1, 1};
        MPI_Aint sdispls[4] = {ind(1,1), ind(1,by), ind(1,1), ind(bx,1)}; /* N, S, W, E */
        MPI_Aint rdispls[4] = {ind(1,0), ind(1,by+1), ind(0,1), ind(bx+1,1)};
        MPI_Datatype types[4] = {north_south_type, north_south_type, east_west_type, east_west_type};
        MPI_Neighbor_alltoallw(aold, counts, sdispls, types, anew, counts, rdispls, types, cart_comm);

        /* update grid points */
        update_grid(bx, by, aold, anew, &heat);

        /* swap working arrays */
        tmp = anew; anew = aold; aold = tmp;

        /* optional - print image */
        if (iter == niters-1)
            printarr_par(iter, anew, n, px, py, coords[0], coords[1],
                         bx, by, offx, offy, MPI_COMM_WORLD);
    }

    t2 = MPI_Wtime();

    /* free working arrays and communication buffers */
    MPI_Free_mem(aold);
    MPI_Free_mem(anew);

    MPI_Type_free(&east_west_type);
    MPI_Type_free(&north_south_type);

    /* get final heat in the system */
    MPI_Allreduce(&heat, &rheat, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
    if (!rank) printf("[%i] last heat: %f time: %f\n", rank, rheat, t2-t1);

    MPI_Finalize();
}