예제 #1
0
void GL_widget_2::smooth_zoom(double x_min, double x_max, double y_min, double y_max) {
	double o_x_min = xmin;
	double o_x_max = xmax;
	double o_y_min = ymin;
	double o_y_max = ymax;
	if (o_x_min == x_min && o_x_max == x_max && o_y_min == y_min && o_y_max == y_max) return;

	QSettings settings;
	int min_squared_distance = settings.value("navigation-smooth-zoom-steps").toInt();
//	std::cout << "navigation-smooth-zoom-steps: " << min_squared_distance << std::endl;

	// these parameters should be moved outside, ini file or user interface...
	double uniform_ratio = 1.00;
	double total_steps = min_squared_distance;//SMOOTH_ZOOM_STEPS;
	
	double uniform_steps = (int) total_steps * uniform_ratio;
	double accel_steps = (int) total_steps - uniform_steps;

	double c_x_min = o_x_min; double x_min_step = uniform_ratio * (x_min - o_x_min)/uniform_steps;
	double c_x_max = o_x_max; double x_max_step = uniform_ratio * (x_max - o_x_max)/uniform_steps;
	double c_y_min = o_y_min; double y_min_step = uniform_ratio * (y_min - o_y_min)/uniform_steps;
	double c_y_max = o_y_max; double y_max_step = uniform_ratio * (y_max - o_y_max)/uniform_steps;
	for (int i=0; i<uniform_steps; i++) {
		c_x_min += x_min_step;
		c_x_max += x_max_step;
		c_y_min += y_min_step;
		c_y_max += y_max_step;
		set_window(c_x_min, c_x_max, c_y_min, c_y_max);
//		msg("ren");
	}

	if (accel_steps==0) return;
	double acc_x_min = ((1-uniform_ratio) * (x_min - o_x_min) - x_min_step * accel_steps) / accel_steps / accel_steps;
	double acc_x_max = ((1-uniform_ratio) * (x_max - o_x_max) - x_max_step * accel_steps) / accel_steps / accel_steps;
	double acc_y_min = ((1-uniform_ratio) * (y_min - o_y_min) - y_min_step * accel_steps) / accel_steps / accel_steps;
	double acc_y_max = ((1-uniform_ratio) * (y_max - o_y_max) - y_max_step * accel_steps) / accel_steps / accel_steps;
	double a_x_min = c_x_min;
	double a_x_max = c_x_max;
	double a_y_min = c_y_min;
	double a_y_max = c_y_max;
	for (int i=1; i<accel_steps+1; i++) {
		a_x_min = c_x_min + x_min_step*i + acc_x_min * i*i;
		a_x_max = c_x_max + x_max_step*i + acc_x_max * i*i;
		a_y_min = c_y_min + y_min_step*i + acc_y_min * i*i;
		a_y_max = c_y_max + y_max_step*i + acc_y_max * i*i;
		set_window(a_x_min, a_x_max, a_y_min, a_y_max);
	}
}
예제 #2
0
STDMETHODIMP CamShiftTracker::Process(IplImage *image)
{
    HRESULT hr = MatchFormat(image, &m_image_format);
    if (FAILED(hr))
        return hr;

    if (m_calibrate > 0)
    {
        CvRect rect = cvRect(image->width*0.47, image->height*0.47, image->width*0.06, image->height*0.07);
        cvRectangle(image, cvPoint(rect.x, rect.y), cvPoint(rect.x+rect.width, rect.y+rect.height), 0xffffff, 1);
        set_window(rect);
        update_histogram(static_cast<CvImage *>(image));
        m_calibrate--;
    }
    //else
    {
        track_object(static_cast<CvImage *>(image));

        CvRect rect = get_window();
        CvPoint center = cvPoint(rect.x + rect.width/2, rect.y + rect.height/2);
        DrawCross(image, center);
        cvRectangle(image, cvPoint(rect.x, rect.y), cvPoint(rect.x+rect.width, rect.y+rect.height), 0xffffff, 1);
    }

    return NOERROR;
}
예제 #3
0
/*
 * Fill a rectangle with specified color.
 */
static void s6d04h0_fill_rectangle(int x0, int y0, int x1, int y1, int color)
{
    if (x0 < 0) x0 = 0;
    if (y0 < 0) x0 = 0;
    if (x1 < 0) x1 = 0;
    if (y1 < 0) x1 = 0;
    if (x0 >= _width) x0 = _width-1;
    if (x1 >= _width) x1 = _width-1;
    if (y0 >= _height) y0 = _height-1;
    if (y1 >= _height) y1 = _height-1;

    if (x1 < x0) {
        int t = x0;
        x0 = x1;
        x1 = t;
    }
    if (y1 < y0) {
        int t = y0;
        y0 = y1;
        y1 = t;
    }
    gpanel_cs_active();
    set_window(x0, y0, x1, y1);
    flood(color, (x1 - x0 + 1) * (y1 - y0 + 1));
    gpanel_cs_idle();
}
예제 #4
0
/*
 * Draw a glyph of one symbol.
 */
static void s6d04h0_draw_glyph(const struct gpanel_font_t *font,
    int color, int background, int x, int y, int width,
    const unsigned short *bits)
{
    int h, w, c;
    unsigned bitmask = 0;

    if (background >= 0) {
        /*
         * Clear background.
         */
        gpanel_cs_active();
        set_window(x, y, x + width - 1, y + font->height - 1);
        gpanel_rs_data();

        /* Loop on each glyph row. */
        for (h=0; h<font->height; h++) {
            /* Loop on every pixel in the row (left to right). */
            for (w=0; w<width; w++) {
                if ((w & 15) == 0)
                    bitmask = *bits++;
                else
                    bitmask <<= 1;

                c = (bitmask & 0x8000) ? color : background;
                gpanel_write_byte(c >> 8);
                gpanel_write_byte(c);
            }
        }
        gpanel_cs_idle();
    } else {
예제 #5
0
파일: ILI9320.hpp 프로젝트: dx168b/muil
void ILI9320Display<Connector, ResetPin>::paint_character(
	int           x0,
	int           y0,
	const uint8_t *data,
	uint8_t       width,
	uint8_t       height,
	const Color   &color,
	const Color   *bg_color)
{
	x0 += offset_x_;
	y0 += offset_y_;
	const uint16_t w8 = (width + 7) / 8;
	const uint16_t color_v = rgb_to_value(color);
	int16_t y = y0;
	for (; height != 0; height--, y++)
	{
		int32_t x = x0;
		for (uint16_t i = 0; i < w8; i++)
		{
			uint8_t value = *data++;
			for (uint8_t j = 0; j < 8; j++)
			{
				if (crd_is_ok(x, y) && (value & 0x80))
				{
					set_window(x, y, x, y);
					write_reg(0x0022, color_v);
				}
				x++;
				value <<= 1;
			}
		}
	}
}
예제 #6
0
void GLCanvas::zoom_to(float zoom_level)
{
   zoom_level = clamp(zoom_level, Params::zoom_range()) ;
   float zoom_factor = zoom_level/m_zoom_level ;
   m_zoom_level = zoom_level ;

   float current_width  = m_window[RIGHT] - m_window[LEFT] ;
   float current_height = m_window[TOP] - m_window[BOTTOM] ;

   float new_width  = current_width /zoom_factor ;
   float new_height = current_height/zoom_factor ;

   float width_incr  = abs((new_width  - current_width )/2) ;
   float height_incr = abs((new_height - current_height)/2) ;

   if (new_width > current_width) // zoom-out
   {
      m_window[LEFT]   -= width_incr ;
      m_window[RIGHT]  += width_incr ;
      m_window[BOTTOM] -= height_incr ;
      m_window[TOP]    += height_incr ;
   }
   else // zoom-in
   {
      m_window[LEFT]   += width_incr ;
      m_window[RIGHT]  -= width_incr ;
      m_window[BOTTOM] += height_incr ;
      m_window[TOP]    -= height_incr ;
   }
   set_window(m_window) ;
}
예제 #7
0
파일: display.cpp 프로젝트: nevilc/YomiDS
void Display::resize(unsigned char w_, unsigned char h_){
	// Clear current area, resize, then mark dirty
	set_window();
	ansi::clear();
	_w = w_;
	_h = h_;
	_dirty = true;
}
예제 #8
0
파일: display.cpp 프로젝트: nevilc/YomiDS
void Display::move(unsigned char x_, unsigned char y_){
	// Clear current area, move, then mark dirty
	set_window();
	ansi::clear();
	_x = x_;
	_y = y_;
	_dirty = true;
}
예제 #9
0
파일: ILI9320.hpp 프로젝트: dx168b/muil
void ILI9320Display<Connector, ResetPin>::set_point(int x, int y, const Color &color)
{
	x += offset_x_;
	y += offset_y_;
	if ( !crd_is_ok(x, y) ) return;
	set_window(x, y, x, y);
	write_reg(0x0022, rgb_to_value(color));
}
예제 #10
0
void GLCanvas::pan(float dx, float dy)
{
   m_window[LEFT]   += dx ;
   m_window[RIGHT]  += dx ;
   m_window[BOTTOM] += dy ;
   m_window[TOP]    += dy ;

   set_window(m_window) ;
}
예제 #11
0
파일: display.cpp 프로젝트: nevilc/YomiDS
void Display::draw(){
	if (_enabled){
		if (_dirty){
			set_window();
			ansi::clear();
			_draw();
			_dirty = false;
		}
	}
}
예제 #12
0
/*
 * Draw a pixel.
 */
static void s6d04h0_set_pixel(int x, int y, int color)
{
    if (x < 0 || x >= _width || y < 0 || y >= _height)
        return;
    gpanel_cs_active();
    set_window(x, y, x, y);
    write_data(color >> 8);
    write_data(color);
    gpanel_cs_idle();
}
예제 #13
0
STDMETHODIMP CamShiftTracker::SetFormat(IplImage *image_header)
{
    HRESULT hr = CheckFormat(image_header);
    if (FAILED(hr))
        return hr;

    m_image_format = *image_header;

    set_window(cvRect(0, 0, image_header->width, image_header->height));

    return NOERROR;
}
예제 #14
0
void GL_widget_2::set_window_to_boundingbox() {
	if (default_bounding_box) return;
	double margin_percent=BOUNDING_BOX_MARGIN_PERCENT;
	double x_min = bounding_xmin;
	double x_max = bounding_xmax;
	double y_min = bounding_ymin;
	double y_max = bounding_ymax;
	double x_margin = (x_max - x_min) * margin_percent;
	double y_margin = (y_max - y_min) * margin_percent;
	x_min -= x_margin;	x_max += x_margin;
	y_min -= y_margin;	y_max += y_margin;
	set_window(x_min, x_max, y_min, y_max);
}
예제 #15
0
static void s6d04h0_clear(struct gpanel_hw *h, int color, int width, int height)
{
    gpanel_cs_active();

    /* Switch screen orientaation. */
    if (width > height)
        set_rotation(1);        /* Landscape */
    else if (width < height)
        set_rotation(0);        /* Portrait */

    /* Fill the screen with a color. */
    set_window(0, 0, _width-1, _height-1);
    flood(color, _width * _height);
    gpanel_cs_idle();
}
예제 #16
0
void TEventWindow::create_window(pchar caption, TWin *parent)
//-------------------------------------------------------------------
{
 HWND hParent;
 void *CreatParms[2];
 pre_create();
 m_dc = new TDC;
 CreatParms[0] = (void *)this;
 if (parent) hParent = parent->handle(); else hParent = NULL;
 m_hwnd = CreateWindow (EW_CLASSNAME, caption, m_style,
            CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,
            hParent,NULL, hInst, CreatParms);
 if(m_style & WS_VSCROLL) m_sb_vert = new TScrollBar(m_hwnd,SB_VERT);
 set_window();
}
예제 #17
0
/*
 * Fill a rectangle with user data.
 */
static void s6d04h0_draw_image(int x, int y, int width, int height,
    const unsigned short *data)
{
    unsigned cnt = width * height;
    int color;

    gpanel_cs_active();
    set_window(x, y, x + width - 1, y + height - 1);
    gpanel_rs_data();
    while (cnt--) {
        color = *data++;
        gpanel_write_byte(color >> 8);
        gpanel_write_byte(color);
    }
    gpanel_cs_idle();
}
static void
gedit_collaboration_window_helper_dispose (GObject *object)
{
	GeditCollaborationWindowHelper *helper = GEDIT_COLLABORATION_WINDOW_HELPER (object);

	if (helper->priv->window)
	{
		set_window (helper, NULL);
	}

	if (helper->priv->manager)
	{
		g_object_unref (helper->priv->manager);
		helper->priv->manager = NULL;
	}
}
예제 #19
0
파일: screen.c 프로젝트: Hoffa/nFrotz
static void erase_screen (zword win)
{
    int i;

    os_erase_area (1, 1, h_screen_height, h_screen_width);

    if ((short) win == -1) {
        split_window (0);
        set_window (0);
        reset_cursor (0);
    }

    for (i = 0; i < 8; i++)
        wp[i].line_count = 0;

}/* erase_screen */
예제 #20
0
static void erase_screen (zword win)
{
    int i;

    if (hi (cwp->colour) != TRANSPARENT_COLOUR)
        os_erase_area (1, 1, h_screen_height, h_screen_width, -2);

    if ((short) win == -1) {
        split_window (0);
        set_window (0);
        reset_cursor (0);
    }

    for (i = 0; i < 8; i++)
        wp[i].line_count = 0;

}/* erase_screen */
예제 #21
0
파일: ILI9320.hpp 프로젝트: dx168b/muil
void ILI9320Display<Connector, ResetPin>::fill_rect(const Rect &rect, const Color &color)
{
	int16_t x1, y1, x2, y2;
	bool ok = detailed::check_and_correct_rect_coords(
		rect,
		get_width(),
		get_height(),
		offset_x_,
		offset_y_,
		x1, y1, x2, y2
	);

	if (!ok) return;
	const uint16_t color_v = rgb_to_value(color);
	set_window(x1, y1, x2, y2);
	Connector::write_index(0x0022);
	Connector::write_data16(color_v, (x2 - x1 + 1) * (y2 - y1 + 1));
}
static void
gedit_collaboration_window_helper_set_property (GObject      *object,
                                                guint         prop_id,
                                                const GValue *value,
                                                GParamSpec   *pspec)
{
	GeditCollaborationWindowHelper *self = GEDIT_COLLABORATION_WINDOW_HELPER (object);

	switch (prop_id)
	{
		case PROP_WINDOW:
			set_window (self, g_value_get_object (value));
		break;
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}
예제 #23
0
파일: diagwin.C 프로젝트: ggcov/ggcov
diagwin_t::diagwin_t(diagram_t *di)
{
    GladeXML *xml;

    zoom_ = 1.0;
    diagram_ = di;

    /* load the interface & connect signals */
    xml = ui_load_tree("diag");

    set_window(glade_xml_get_widget(xml, "diag"));
    set_title(diagram_->title());

    canvas_ = glade_xml_get_widget(xml, "diag_canvas");
    gnome_canvas_set_pixels_per_unit(GNOME_CANVAS(canvas_), zoom_);

    ui_register_windows_menu(ui_get_dummy_menu(xml, "diag_windows_dummy"));
}
예제 #24
0
bool
AeHandler::set_window (XCam3AWindow *window, uint8_t count)
{
    if (0 == count) {
        XCAM_LOG_WARNING ("invalid input parameter, window count = %d, reset to default value", count);
        XCam3AWindow defaultWindow = {0, 0, 1000, 1000, 15};
        set_window(&defaultWindow);
        _params.window_list[0] = defaultWindow;
        return true;
    }

    if (XCAM_AE_MAX_METERING_WINDOW_COUNT < count) {
        XCAM_LOG_WARNING ("invalid input parameter, window count = %d, reset count to maximum", count);
        count = XCAM_AE_MAX_METERING_WINDOW_COUNT;
    }

    AnalyzerHandler::HanlderLock lock(this);

    _params.window = *window;

    for (int i = 0; i < count; i++) {
        XCAM_LOG_DEBUG ("window start point(%d, %d), end point(%d, %d), weight = %d",
                        window[i].x_start, window[i].y_start, window[i].x_end, window[i].y_end, window[i].weight);

        _params.window_list[i] = window[i];
        if (_params.window.weight < window[i].weight) {
            _params.window.weight = window[i].weight;
            _params.window.x_start = window[i].x_start;
            _params.window.y_start = window[i].y_start;
            _params.window.x_end = window[i].x_end;
            _params.window.y_end = window[i].y_end;
        }
    }

    XCAM_LOG_DEBUG ("ae set metering mode window [x:%d, y:%d, x_end:%d, y_end:%d, weight:%d]",
                    _params.window.x_start,
                    _params.window.y_start,
                    _params.window.x_end,
                    _params.window.y_end,
                    _params.window.weight);

    return true;
}
void MyWidget::on_realize()
{
  //Do not call base class Gtk::Widget::on_realize().
  //It's intended only for widgets that set_has_window(false).

  set_realized();

  //Get the themed style from the CSS file:
  get_style_property("example_scale", m_scale);
  std::cout << "m_scale (example_scale from the theme/css-file) is: "
      << m_scale << std::endl;

  if(!m_refGdkWindow)
  {
    //Create the GdkWindow:

    GdkWindowAttr attributes;
    memset(&attributes, 0, sizeof(attributes));

    Gtk::Allocation allocation = get_allocation();

    //Set initial position and size of the Gdk::Window:
    attributes.x = allocation.get_x();
    attributes.y = allocation.get_y();
    attributes.width = allocation.get_width();
    attributes.height = allocation.get_height();

    attributes.event_mask = get_events () | Gdk::EXPOSURE_MASK;
    attributes.window_type = GDK_WINDOW_CHILD;
    attributes.wclass = GDK_INPUT_OUTPUT;

    m_refGdkWindow = Gdk::Window::create(get_parent_window(), &attributes,
            GDK_WA_X | GDK_WA_Y);
    set_window(m_refGdkWindow);

    //set colors
    override_background_color(Gdk::RGBA("red"));
    override_color(Gdk::RGBA("blue"));

    //make the widget receive expose events
    m_refGdkWindow->set_user_data(gobj());
  }
}
예제 #26
0
static void
pluma_documents_panel_set_property (GObject      *object,
				    guint         prop_id,
				    const GValue *value,
				    GParamSpec   *pspec)
{
	PlumaDocumentsPanel *panel = PLUMA_DOCUMENTS_PANEL (object);

	switch (prop_id)
	{
		case PROP_WINDOW:
			set_window (panel, g_value_get_object (value));
			break;

		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
			break;
	}
}
예제 #27
0
static int control(uint32_t request, void *data, ...)
{
  switch (request) {
  case VOCTRL_QUERY_FORMAT:
    return query_format(*((uint32_t*)data));
  case VOCTRL_GET_IMAGE:
    return get_image(data);
  case VOCTRL_DRAW_IMAGE:
    return draw_image(data);
  case VOCTRL_START_SLICE:
    return start_slice(data);
  case VOCTRL_FULLSCREEN:
    return fullscreen();
  case VOCTRL_XOVERLAY_SUPPORT:
    return VO_TRUE;
  case VOCTRL_XOVERLAY_SET_COLORKEY:
    return set_colorkey(data);
  case VOCTRL_XOVERLAY_SET_WIN:
    return set_window(data);
  }
  return VO_NOTIMPL;
}
예제 #28
0
/**
* Does something when the block bar is realized.
*/
void GtkBlockBar::on_realize()
{
	//Do not call base class Gtk::Widget::on_realize().
	//It's intended only for widgets that set_has_window(false).

	set_realized();

	if(!m_refGdkWindow)
	{
		//Create the GdkWindow:

		GdkWindowAttr attributes;
		memset(&attributes, 0, sizeof(attributes));

		Gtk::Allocation allocation = get_allocation();

		//Set initial position and size of the Gdk::Window:
		attributes.x = allocation.get_x();
		attributes.y = allocation.get_y();
		attributes.width = allocation.get_width();
		attributes.height = allocation.get_height();

		attributes.event_mask = get_events () | Gdk::EXPOSURE_MASK;
		attributes.window_type = GDK_WINDOW_CHILD;
		attributes.wclass = GDK_INPUT_OUTPUT;

		m_refGdkWindow = Gdk::Window::create(get_parent_window(), &attributes,
		                                     GDK_WA_X | GDK_WA_Y);
		set_window(m_refGdkWindow);

		//set colors TODO
		//override_background_color(Gdk::RGBA("red"));
		//override_color(Gdk::RGBA("green"));

		//make the widget receive expose events
		m_refGdkWindow->set_user_data(gobj());
	}
}
예제 #29
0
파일: clamr_quo.cpp 프로젝트: brtnfld/CLAMR
int main(int argc, char **argv) {

   //  Process command-line arguments, if any.
   int mype=0;
   int numpe=0;
   parseInput(argc, argv);
   L7_Init(&mype, &numpe, &argc, argv);

#if 1 // SKG make things sane for debugging
   signal(SIGSEGV, SIG_DFL);
#endif

   struct timeval tstart_setup;
   cpu_timer_start(&tstart_setup);

   real_t circ_radius = 6.0;
   //  Scale the circle appropriately for the mesh size.
   circ_radius = circ_radius * (real_t) nx / 128.0;
   int boundary = 1;
   int parallel_in = 1;

   // figure out the max number of threads that can be spawned
   if (0 == mype) {
        int nt = omp_get_max_threads();
        printf("--- num openmp threads: %d\n", nt);
        fflush(stdout);
   }

   mesh = new Mesh(nx, ny, levmx, ndim, boundary, parallel_in, do_gpu_calc);
   if (DEBUG) {
      //if (mype == 0) mesh->print();

      char filename[10];
      sprintf(filename,"out%1d",mype);
      mesh->fp=fopen(filename,"w");

      //mesh->print_local();
   }
   mesh->init(nx, ny, circ_radius, initial_order, do_gpu_calc);

   size_t &ncells = mesh->ncells;
   size_t &ncells_global = mesh->ncells_global;
   int &noffset = mesh->noffset;

   state = new State(mesh);
   state->init(do_gpu_calc);

   vector<int>   &nsizes     = mesh->nsizes;
   vector<int>   &ndispl     = mesh->ndispl;

   vector<spatial_t> &x  = mesh->x;
   vector<spatial_t> &dx = mesh->dx;
   vector<spatial_t> &y  = mesh->y;
   vector<spatial_t> &dy = mesh->dy;

   nsizes.resize(numpe);
   ndispl.resize(numpe);

   int ncells_int = ncells;
   MPI_Allgather(&ncells_int, 1, MPI_INT, &nsizes[0], 1, MPI_INT, MPI_COMM_WORLD);

   ndispl[0]=0;
   for (int ip=1; ip<numpe; ip++){
      ndispl[ip] = ndispl[ip-1] + nsizes[ip-1];
   }
   noffset = ndispl[mype];

   state->resize(ncells);

   state->fill_circle(circ_radius, 100.0, 7.0);

   x.clear();
   dx.clear();
   y.clear();
   dy.clear();

   //  Kahan-type enhanced precision sum implementation.
   double H_sum = state->mass_sum(enhanced_precision_sum);
   if (mype == 0) printf ("Mass of initialized cells equal to %14.12lg\n", H_sum);
   H_sum_initial = H_sum;

   double cpu_time_main_setup = cpu_timer_stop(tstart_setup);
   mesh->parallel_timer_output("CPU:  setup time               time was",cpu_time_main_setup, 0);

   long long mem_used = memstats_memused();
   if (mem_used > 0) {
      mesh->parallel_memory_output("Memory used      in startup ",mem_used, 0);
      mesh->parallel_memory_output("Memory peak      in startup ",memstats_mempeak(), 0);
      mesh->parallel_memory_output("Memory free      at startup ",memstats_memfree(), 0);
      mesh->parallel_memory_output("Memory available at startup ",memstats_memtotal(), 0);
   }

   if (mype == 0) {
      printf("Iteration   0 timestep      n/a Sim Time      0.0 cells %ld Mass Sum %14.12lg\n", ncells_global, H_sum);
   }

   for (int i = 0; i < MESH_COUNTER_SIZE; i++){
      mesh->cpu_counters[i]=0;
   }
   for (int i = 0; i < MESH_TIMER_SIZE; i++){
      mesh->cpu_timers[i]=0.0;
   }

#ifdef HAVE_GRAPHICS
#ifdef HAVE_OPENGL
   set_mysize(ncells_global);
   //vector<state_t> H_global;
   //vector<spatial_t> x_global;
   //vector<spatial_t> dx_global;
   //vector<spatial_t> y_global;
   //vector<spatial_t> dy_global;
   //vector<int> proc_global;
   if (mype == 0){
      H_global.resize(ncells_global);
      x_global.resize(ncells_global);
      dx_global.resize(ncells_global);
      y_global.resize(ncells_global);
      dy_global.resize(ncells_global);
      proc_global.resize(ncells_global);
   }
   MPI_Gatherv(&x[0],  nsizes[mype], MPI_SPATIAL_T, &x_global[0],  &nsizes[0], &ndispl[0], MPI_SPATIAL_T, 0, MPI_COMM_WORLD);
   MPI_Gatherv(&dx[0], nsizes[mype], MPI_SPATIAL_T, &dx_global[0], &nsizes[0], &ndispl[0], MPI_SPATIAL_T, 0, MPI_COMM_WORLD);
   MPI_Gatherv(&y[0],  nsizes[mype], MPI_SPATIAL_T, &y_global[0],  &nsizes[0], &ndispl[0], MPI_SPATIAL_T, 0, MPI_COMM_WORLD);
   MPI_Gatherv(&dy[0], nsizes[mype], MPI_SPATIAL_T, &dy_global[0], &nsizes[0], &ndispl[0], MPI_SPATIAL_T, 0, MPI_COMM_WORLD);
   MPI_Gatherv(&state->H[0], nsizes[mype], MPI_STATE_T, &H_global[0], &nsizes[0], &ndispl[0], MPI_STATE_T, 0, MPI_COMM_WORLD);

   set_cell_data(&H_global[0]);
   set_cell_coordinates(&x_global[0], &dx_global[0], &y_global[0], &dy_global[0]);

   if (view_mode == 0) {
      mesh->proc.resize(ncells);
      for (size_t ii = 0; ii<ncells; ii++){
         mesh->proc[ii] = mesh->mype;
      }
   
      MPI_Gatherv(&mesh->proc[0],  nsizes[mype], MPI_INT, &proc_global[0],  &nsizes[0], &ndispl[0], MPI_C_REAL, 0, MPI_COMM_WORLD);
   }

   set_cell_proc(&proc_global[0]);
#endif
#ifdef HAVE_MPE
   set_mysize(ncells);
   set_cell_data(&state->H[0]);
   set_cell_coordinates(&mesh->x[0], &mesh->dx[0], &mesh->y[0], &mesh->dy[0]);
   set_cell_proc(&mesh->proc[0]);
#endif

   set_window((float)mesh->xmin, (float)mesh->xmax, (float)mesh->ymin, (float)mesh->ymax);
   set_viewmode(view_mode);
   set_outline((int)outline);
   init_display(&argc, argv, "Shallow Water");

   set_circle_radius(circle_radius);
   draw_scene();
   if (verbose) sleep(5);
   sleep(2);

   //  Set flag to show mesh results rather than domain decomposition.
   view_mode = 1;
   
   //  Clear superposition of circle on grid output.
   circle_radius = -1.0;
   
   MPI_Barrier(MPI_COMM_WORLD);
   cpu_timer_start(&tstart);

   set_idle_function(&do_calc);
   start_main_loop();
#else
   MPI_Barrier(MPI_COMM_WORLD);
   cpu_timer_start(&tstart);
   for (int it = 0; it < 10000000; it++) {
      do_calc();
   }
#endif
   
   return 0;
}
예제 #30
0
int main(int argc, char **argv) {

    // Needed for code to compile correctly on the Mac
   int mype=0;
   int numpe=-1;

   //  Process command-line arguments, if any.
   parseInput(argc, argv);

   struct timeval tstart_setup;
   cpu_timer_start(&tstart_setup);
   
   numpe = 16;

   double circ_radius = 6.0;
   //  Scale the circle appropriately for the mesh size.
   circ_radius = circ_radius * (double) nx / 128.0;
   int boundary = 1;
   int parallel_in = 0;
   
   mesh  = new Mesh(nx, ny, levmx, ndim, boundary, parallel_in, do_gpu_calc);
   if (DEBUG) {
      //if (mype == 0) mesh->print();

      char filename[10];
      sprintf(filename,"out%1d",mype);
      mesh->fp=fopen(filename,"w");

      //mesh->print_local();
   } 
   mesh->init(nx, ny, circ_radius, initial_order, do_gpu_calc);
   size_t &ncells = mesh->ncells;
   state = new State(mesh);
   state->init(do_gpu_calc);
   mesh->proc.resize(ncells);
   mesh->calc_distribution(numpe);
   state->fill_circle(circ_radius, 100.0, 5.0);
   mesh->nlft = NULL;
   mesh->nrht = NULL;
   mesh->nbot = NULL;
   mesh->ntop = NULL;
   
   //  Kahan-type enhanced precision sum implementation.
   double H_sum = state->mass_sum(enhanced_precision_sum);
   printf ("Mass of initialized cells equal to %14.12lg\n", H_sum);
   H_sum_initial = H_sum;

   double cpu_time_main_setup = cpu_timer_stop(tstart_setup);
   state->parallel_timer_output(numpe,mype,"CPU:  setup time               time was",cpu_time_main_setup);

   long long mem_used = memstats_memused();
   if (mem_used > 0) {
      printf("Memory used      in startup %lld kB\n",mem_used);
      printf("Memory peak      in startup %lld kB\n",memstats_mempeak());
      printf("Memory free      at startup %lld kB\n",memstats_memfree());
      printf("Memory available at startup %lld kB\n",memstats_memtotal());
   }

   printf("Iteration   0 timestep      n/a Sim Time      0.0 cells %ld Mass Sum %14.12lg\n", ncells, H_sum);

   mesh->cpu_calc_neigh_counter=0;
   mesh->cpu_time_calc_neighbors=0.0;
   mesh->cpu_rezone_counter=0;
   mesh->cpu_time_rezone_all=0.0;
   mesh->cpu_refine_smooth_counter=0;

   //  Set up grid.
#ifdef GRAPHICS_OUTPUT
   mesh->write_grid(n);
#endif

#ifdef HAVE_GRAPHICS
   set_mysize(ncells);
   set_viewmode(view_mode);
   set_window(mesh->xmin, mesh->xmax, mesh->ymin, mesh->ymax);
   set_outline((int)outline);
   init_display(&argc, argv, "Shallow Water", mype);
   set_cell_coordinates(&mesh->x[0], &mesh->dx[0], &mesh->y[0], &mesh->dy[0]);
   set_cell_data(&state->H[0]);
   set_cell_proc(&mesh->proc[0]);
   set_circle_radius(circle_radius);
   draw_scene();
   //if (verbose) sleep(5);
   sleep(2);

   //  Set flag to show mesh results rather than domain decomposition.
   view_mode = 1;

   //  Clear superposition of circle on grid output.
   circle_radius = -1.0;

   cpu_timer_start(&tstart);

   set_idle_function(&do_calc);
   start_main_loop();
#else
   cpu_timer_start(&tstart);
   for (int it = 0; it < 10000000; it++) {
      do_calc();
   }
#endif
   
   return 0;
}