⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grph.c

📁 mpi 结合vc编程用模拟退火法算一个最小路径的值
💻 C
📖 第 1 页 / 共 2 页
字号:
	fprintf( ctx->fp, "wait\nnew page\n" );
}

/*
    GNUplot output 
 */
void HeaderGnuplot( GraphData ctx, char *protocol_name, 
		    char *title_string, char *units )
{
    char archname[20], hostname[256], date[30], *p;
    int  dummy;

    if (!ctx) return;

    switch (ctx->output_type) {
    case GRF_EPS:
	fprintf( ctx->fp, "set terminal postscript eps\n" );
	break;
    case GRF_PS:
	fprintf( ctx->fp, "set terminal postscript\n" );
	break;
    case GRF_GIF:
	fprintf( ctx->fp, "set terminal gif\n" );
	break;
    case GRF_X:
	/* Default behavior */
	break;
    }
    fprintf( ctx->fp, "set xlabel \"Size %s\"\n", units );
    fprintf( ctx->fp, "set ylabel \"time (us)\"\n" );
    if (ctx->is_log) 
	fprintf( ctx->fp, "set logscale xy\n" );
    strcpy(archname,"MPI" );
    MPI_Get_processor_name(hostname,&dummy);
/* Must remove ' from hostname */
    p = hostname;
    while (*p) {
	if (*p == '\'') *p = ' ';
	p++;
    }
    strcpy(date , "Not available" );
    if (!date[0] || strcmp( "Not available", date ) == 0) {
	fprintf( ctx->fp, "set title \"Comm Perf for %s (%s) type %s\"\n", 
		 archname, hostname, protocol_name );
    }
    else {
	fprintf( ctx->fp, "set title \"Comm Perf for %s (%s) on %s type %s\"\n", 
		 archname, hostname, date, protocol_name );
    }
    fprintf( ctx->fpdata, "\n#p0\tp1\tdist\tlen\tave time (us)\trate\n");
    fflush( ctx->fp );
}

void HeaderForGopGnuplot( GraphData ctx, char *protocol_name, 
			  char *title_string, char *units )
{
    char archname[20], hostname[256], date[30], *p;
    int  dummy;

    if (!ctx) return;

    fprintf( ctx->fp, "set xlabel \"Processes\"\n" );
    fprintf( ctx->fp, "set ylabel \"time (us)\"\n" );

    strcpy(archname,"MPI" );
    MPI_Get_processor_name(hostname,&dummy);
/* Must remove ' from hostname */
    p = hostname;
    while (*p) {
	if (*p == '\'') *p = ' ';
	p++;
    }
    strcpy(date , "Not available" );
    if (!date[0] || strcmp( "Not available", date ) == 0) {
	fprintf( ctx->fp, "set title \"Comm Perf for %s (%s) type %s\"\n", 
		 archname, hostname, protocol_name );
    }
    else {
	fprintf( ctx->fp, 
		 "set title \"Comm Perf for %s (%s) on %s type %s\"\n", 
		 archname, hostname, date, protocol_name );
    }
    fprintf( ctx->fpdata, "\n#np time (us) for various sizes\n");
    fflush( ctx->fp );
}

void DrawGnuplot( GraphData ctx, int first, int last, double s, double r )
{
    if (!ctx) return;

    if (ctx->givedy) {
	fprintf( ctx->fp, 
		 "plot '%s' using 4:5:7:8 notitle with errorbars", 
		 ctx->fname2 );
    }
    else {
	fprintf( ctx->fp, "plot '%s' using 4:5 notitle with ", ctx->fname2 );

/* Where is the configure test for this? */    
#ifdef GNUVERSION_HAS_BOXES
	fprintf( ctx->fp, "boxes,\\\n\
'%s' using 4:7 with lines", ctx->fname2 );
#else
	fprintf( ctx->fp, "lines" );
#endif
    }
    if (r > 0.0) {
	fprintf( ctx->fp, ",\\\n%f+%f*x with dots\n", 
		 s*1.0e6, r*1.0e6  );
    }
    else {
	fprintf( ctx->fp, "\n" );
    }
}

void DrawGopGnuplot( GraphData ctx, int first, int last, double s, 
		     double r, int nsizes, int *sizelist )
{
    int i;

    if (!ctx) return;

    fprintf( ctx->fp, "plot " );
    for (i=0; i<nsizes; i++) {
#ifdef GNUVERSION_HAS_BOXES
	fprintf( ctx->fp, "'%s' using 1:%d title '%d' with boxes%s\n\
'%s' using 1:%d with lines,\\\n", ctx->fname2, i+2, sizelist[i], 
		 ctx->fname2, i+2, (i == nsizes-1) ? "" : ",\\" );
#else
	fprintf( ctx->fp, "'%s' using 1:%d title '%d' with lines%s\n", 
		 ctx->fname2, i+2, sizelist[i], (i == nsizes-1) ? "" : ",\\" );
#endif
    }
}

/*
   Generate an end-of-page
 */
void EndPageGnuplot( GraphData ctx )
{
    if (!ctx) return;

    if (ctx->is_lastwindow) {
	if (ctx->output_type == GRF_X) 
	    fprintf( ctx->fp, 
		     "pause -1 \"Press <return> to continue\"\nclear\n" );
	else
	    fprintf( ctx->fp, "exit\n" );
    }
}

/* Common operations */
void HeaderGraph( GraphData ctx, char *protocol_name, char *title_string, 
		  char *units )
{
    if (!ctx) return;

    (*ctx->header)( ctx, protocol_name, title_string, units );
}

void HeaderForGopGraph( GraphData ctx, char *protocol_name, 
			char *title_string, char *units )
{
    if (!ctx) return;

    (*ctx->headergop)( ctx, protocol_name, title_string, units );
}

void DrawGraph( GraphData ctx, int first, int last, double s, double r )
{
    if (!ctx) return;

    (*ctx->draw)( ctx, first, last, s, r ) ;
}

void DrawGraphGop( GraphData ctx, int first, int last, double s, double r, 
		   int nsizes, int *sizelist )
{
    if (!ctx) return;

    (*ctx->drawgop)( ctx, first, last, s, r, nsizes, sizelist ) ;
}

void EndPageGraph( GraphData ctx )
{
    if (!ctx) return;

    (*ctx->endpage)( ctx );
}

#define MAX_TSTRING 1024

/* Common create */
GraphData SetupGraph( int *argc, char *argv[] )
{
    GraphData  new;
    char       filename[1024];
    int        wsize[2];
    int        isgnu;
    int        givedy;
    static char tstring[MAX_TSTRING];

    OutputForm output_type = GRF_X;

    new = (GraphData)malloc(sizeof(struct _GraphData));    if (!new)return 0;;

    filename[0] = 0;
    /* Set default.  The gnuplot isn't as nice (separate file for data) */
    isgnu = 0;
#ifdef FOO
#if GRAPHICS_PGM == gnuplot
    isgnu = 1;
#else    
    isgnu = 0;
#endif
#endif
    if (SYArgHasName( argc, argv, 1, "-gnuplot" )) isgnu = 1;
    if (SYArgHasName( argc, argv, 1, "-cit" )) isgnu = 0;

    if (!isgnu) {
	if ((isgnu = SYArgHasName( argc, argv, 1, "-gnuploteps" ))) {
	    output_type = GRF_EPS;
	};
    }
    if (!isgnu) {
	if ((isgnu = SYArgHasName( argc, argv, 1, "-gnuplotps" ))) {
	    output_type = GRF_PS;
	};
    }
    if (!isgnu) {
	if ((isgnu = SYArgHasName( argc, argv, 1, "-gnuplotgif" ))) {
	    output_type = GRF_GIF;
	};
    }

    if (SYArgHasName( argc, argv, 1, "-cit" )) isgnu = 0;
    if (SYArgGetString( argc, argv, 1, "-fname", filename, 1024 ) &&
	__MYPROCID == 0) {
	new->fp = fopen( filename, "a" );
	if (!new->fp) {
	    fprintf( stderr, "Could not open file %s\n", filename );
	    return 0;
	}
    }
    else 
	new->fp = stdout;
    givedy = SYArgHasName( argc, argv, 1, "-givedy" );

    new->do_rate = SYArgHasName( argc, argv, 1, "-rate" );

    new->do_fit  = SYArgHasName( argc, argv, 1, "-fit" );

    if (SYArgGetString( argc, argv, 1, "-title", tstring, MAX_TSTRING ))
	new->title = tstring;
    else
	new->title = 0;

/* Graphics layout */
    new->wxi    = 1;
    new->wxn    = 1;
    new->wyi    = 1;
    new->wyn    = 1;
    new->givedy = givedy;
    if (SYArgGetIntVec( argc, argv, 1, "-wx", 2, wsize )) {
	new->wxi           = wsize[0];
	new->wxn           = wsize[1];
    }
    if (SYArgGetIntVec( argc, argv, 1, "-wy", 2, wsize )) {
	new->wyi           = wsize[0];
	new->wyn           = wsize[1];
    }
    new->is_lastwindow = SYArgHasName( argc, argv, 1, "-lastwindow" );
    if (new->wxn == 1 && new->wyn == 1) new->is_lastwindow = 1;

    /* Scaling type */
    new->is_log = 0;

    new->output_type = output_type;
    if (!isgnu) {
	new->header	= HeaderCIt;
	new->dataout    = DataoutGraph;
	new->headergop  = HeaderForGopCIt;
	new->dataoutgop = DataoutGraphForGop;
	new->draw	= DrawCIt;
	new->drawgop    = DrawGopCIt;
	new->endpage    = EndPageCIt;
	new->endgraph   = EndGraphCIt;
	new->fpdata	= new->fp;
	new->fname2	= 0;
    }
    else {
	char filename2[256];
	new->header	= HeaderGnuplot;
	new->dataout	= DataoutGraph;
	new->headergop	= HeaderForGopGnuplot;
	new->dataoutgop	= DataoutGraphForGop;
	new->draw	= DrawGnuplot;
	new->drawgop	= DrawGopGnuplot;
	new->endpage	= EndPageGnuplot;
	new->endgraph   = EndGraphGnuplot;
	if (filename[0]) {
	    /* Try to remove the extension, if any, from the filename */
	    char *p;
	    strcpy( filename2, filename );
	    p = filename2 + strlen(filename2) - 1;
	    while (p > filename2 && *p != '.') p--;
	    if (p > filename2)
		strcpy( p, ".gpl" );
	    else
		strcat( filename2, ".gpl" );
	}
	else {
	    strcpy( filename2, "mppout.gpl" );
	}
	if (__MYPROCID == 0) {
	    new->fpdata	    = fopen( filename2, "a" );
	    if (!new->fpdata) {
		fprintf( stderr, "Could not open file %s\n\
used for holding data for GNUPLOT\n", filename2 );
		return 0;
	    }
	}
	else 
	    new->fpdata   = 0;
	new->fname2 = (char *)malloc((unsigned)(strlen(filename2 ) + 1 ));
	strcpy( new->fname2, filename2 );
    }
    return new;
}

void DataScale( GraphData ctx, int isLog )
{
    if (!ctx) return;

    ctx->is_log = isLog;
}

void EndGraph( GraphData ctx )
{
    if (!ctx) return;

    (*ctx->endgraph)( ctx );
}

void EndGraphCIt( GraphData ctx )
{
    if (!ctx) return;

    if (ctx->fp && ctx->fp != stdout) fclose( ctx->fp );
}

void EndGraphGnuplot( GraphData ctx )
{
    if (!ctx) return;

    if (ctx->fpdata)                      fclose( ctx->fpdata );
    if (ctx->fp && ctx->fp != stdout)     fclose( ctx->fp );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -