📄 pm_genproc.cpp
字号:
#include <stdlib.h>#include <stdio.h>#include <string.h>#include <ctype.h>#include "mpi.h"//#include "mpe.h"#include "pmandel.h"#include "args.h"/* I used the line:gcc -P -E pm_genproc.c | sed 's/{[]*{/{@{/' | tr "@" "\n" | indent -st > pm_genproc_cleanedup.cto clean this up and see what it looked like. Eek!*//* hope this doesn't cause anybody problems */double drand48();#define DISP(a, b) (int)((char *)(&(a)) - (char *)(&(b)))int DefineMPITypes(){ Flags flags; rect rectangle; MPI_Aint a, b; int len[3]; MPI_Aint disp[3]; MPI_Datatype types[3]; NUM_type = MPI_DOUBLE; MPI_Type_contiguous(6, MPI_INT, &winspecs_type); MPI_Type_commit(&winspecs_type); len[0] = 10; len[1] = 2; len[2] = 6; MPI_Address((void*)&flags.breakout, &a); MPI_Address((void*)&flags, &b); disp[0] = a - b; MPI_Address((void*)&flags.boundary_sq, &a); disp[1] = a - b; MPI_Address((void*)&flags.rmin, &a); disp[2] = a - b; types[0] = MPI_INT; types[1] = MPI_DOUBLE; types[2] = NUM_type; MPI_Type_struct(3, len, disp, types, &flags_type); MPI_Type_commit(&flags_type); len[0] = 5; MPI_Address((void*)&rectangle.l, &a); MPI_Address((void*)&rectangle, &b); disp[0] = a - b; types[0] = MPI_INT; MPI_Type_struct(1, len, disp, types, &rect_type); MPI_Type_commit(&rect_type); return 0;}int GetDefaultWinspecs(Winspecs *winspecs){ winspecs->height = DEF_height; winspecs->width = DEF_width; winspecs->bw = DEF_bw; winspecs->xpos = DEF_xpos; winspecs->ypos = DEF_ypos; winspecs->numColors = DEF_numColors; return 0;}int GetDefaultFlags(Winspecs *winspecs, Flags *flags){ flags->logfile = DEF_logfile; flags->inf = DEF_inf; flags->outf = DEF_outf; flags->winspecs = winspecs; flags->breakout = DEF_breakout; flags->randomize = DEF_randomize; flags->colReduceFactor = DEF_colReduceFactor; flags->loop = DEF_loop; flags->zoom = DEF_zoom; flags->askNeighbor = DEF_askNeighbor; flags->sendMasterComplexity = DEF_sendMasterComplexity; flags->drawBlockRegion = DEF_drawBlockRegion; flags->fractal = DEF_fractal; flags->maxiter = DEF_maxiter; flags->boundary_sq = DEF_boundary * DEF_boundary; flags->epsilon = DEF_epsilon; NUM_ASSIGN(flags->rmin, DEF_rmin); NUM_ASSIGN(flags->rmax, DEF_rmax); NUM_ASSIGN(flags->imin, DEF_imin); NUM_ASSIGN(flags->imax, DEF_imax); NUM_ASSIGN(flags->julia_r, DEF_julia_r); NUM_ASSIGN(flags->julia_i, DEF_julia_i); return 0;}int GetWinspecs(int *argc, char **argv, Winspecs *winspecs){ int myid; MPI_Comm_rank(MPI_COMM_WORLD, &myid); if (!myid) { GetIntArg(argc, argv, "-height", &(winspecs->height)); GetIntArg(argc, argv, "-width", &(winspecs->width)); winspecs->bw = IsArgPresent(argc, argv, "-bw"); GetIntArg(argc, argv, "-xpos", &(winspecs->xpos)); GetIntArg(argc, argv, "-ypos", &(winspecs->ypos)); GetIntArg(argc, argv, "-colors", &(winspecs->numColors)); } MPI_Bcast(winspecs, 1, winspecs_type, 0, MPI_COMM_WORLD); return 0;}int GetFlags(int *argc, char **argv, Winspecs *winspecs, Flags *flags){ double x, y; int myid, strLens[3]; MPI_Comm_rank(MPI_COMM_WORLD, &myid); if (myid == 0) { GetStringArg(argc, argv, "-l", &(flags->logfile)); GetStringArg(argc, argv, "-i", &(flags->inf)); /* if reading from input file, disable zooming */ if (flags->inf) { flags->zoom = 0; } GetStringArg(argc, argv, "-o", &(flags->outf)); GetIntArg(argc, argv, "-breakout", &(flags->breakout)); if (IsArgPresent(argc, argv, "-randomize")) { flags->randomize = 0; } if (IsArgPresent(argc, argv, "+randomize")) { flags->randomize = 1; } GetIntArg(argc, argv, "-colreduce", &(flags->colReduceFactor)); flags->loop = IsArgPresent(argc, argv, "-loop"); if (IsArgPresent(argc, argv, "-zoom")) { flags->zoom = 0; } if (IsArgPresent(argc, argv, "+zoom") && !flags->inf) { flags->zoom = 1; } flags->askNeighbor = IsArgPresent(argc, argv, "-neighbor"); flags->sendMasterComplexity = IsArgPresent(argc, argv, "-complexity"); flags->drawBlockRegion = IsArgPresent(argc, argv, "-delaydraw"); if (IsArgPresent(argc, argv, "-mandel")) { flags->fractal = MBROT; } else if (IsArgPresent(argc, argv, "-julia")) { flags->fractal = JULIA; } else if (IsArgPresent(argc, argv, "-newton")) { flags->fractal = NEWTON; } GetIntArg(argc, argv, "-maxiter", &(flags->maxiter)); if (GetDoubleArg(argc, argv, "-boundary", &x)) { flags->boundary_sq = x * x; } GetDoubleArg(argc, argv, "-epsilon", &(flags->epsilon)); if (GetDoubleArg(argc, argv, "-rmin", &x)) { NUM_ASSIGN(flags->rmin, DBL2NUM(x)); } if (GetDoubleArg(argc, argv, "-rmax", &x)) { NUM_ASSIGN(flags->rmax, DBL2NUM(x)); } if (GetDoubleArg(argc, argv, "-imin", &x)) { NUM_ASSIGN(flags->imin, DBL2NUM(x)); } if (GetDoubleArg(argc, argv, "-imax", &x)) { NUM_ASSIGN(flags->imax, DBL2NUM(x)); } if (GetDoubleArg(argc, argv, "-radius", &x)) { if (GetDoubleArg(argc, argv, "-rcenter", &y)) { NUM_ASSIGN(flags->rmin, DBL2NUM(y-x)); NUM_ASSIGN(flags->rmax, DBL2NUM(y + x)); } if (GetDoubleArg(argc, argv, "-icenter", &y)) { NUM_ASSIGN(flags->imin, DBL2NUM(y-x)); NUM_ASSIGN(flags->imax, DBL2NUM(y + x)); } } strLens[0] = (flags->logfile) ? strlen(flags->logfile) + 1 : 0; strLens[1] = (flags->inf) ? strlen(flags->inf) + 1 : 0; strLens[2] = (flags->outf) ? strlen(flags->outf) + 1 : 0; } /* End of myid == 0 */ MPI_Bcast(flags, 1, flags_type, 0, MPI_COMM_WORLD); MPI_Bcast(strLens, 3, MPI_INT, 0, MPI_COMM_WORLD); if (myid != 0) { flags->logfile = (strLens[0]) ? (char *)malloc(strLens[0] * sizeof(char)) : 0; flags->inf = (strLens[1]) ? (char *)malloc(strLens[1] * sizeof(char)) : 0; flags->outf = (strLens[2]) ? (char *)malloc(strLens[2] * sizeof(char)) : 0; } if (strLens[0]) MPI_Bcast(flags->logfile, strLens[0], MPI_CHAR, 0, MPI_COMM_WORLD); if (strLens[1]) MPI_Bcast(flags->inf, strLens[1], MPI_CHAR, 0, MPI_COMM_WORLD); if (strLens[2]) MPI_Bcast(flags->outf, strLens[2], MPI_CHAR, 0, MPI_COMM_WORLD); return 0;}int Pixel2Complex(Flags *flags, int x, int y, NUM *nx, NUM *ny){ NUM_PTR_ASSIGN( nx, NUM_ADD( NUM_MULT( DBL2NUM((double)x / flags->winspecs->width), NUM_SUB(flags->rmax, flags->rmin)), flags->rmin) ); NUM_PTR_ASSIGN( ny, NUM_ADD( NUM_MULT( DBL2NUM((double)y / flags->winspecs->height), NUM_SUB(flags->imin, flags->imax)), flags->imax) ); /* fprintf(stderr, "In (%d %d) to (%lf,%lf)-(%lf,%lf)\n", flags->winspecs->width, flags->winspecs->height, flags->rmin, flags->imin, flags->rmax, flags->imax); fprintf(stderr, "Converted (%d, %d) to (%lf, %lf)\n", x, y, *nx, *ny); */ return 0;}int StrContainsNonWhiteSpace(char *str){ while (*str) { if (!isspace(*str)) return 1; str++; } return 0;}/* Q_Create - create the queue */void Q_Create(rect_queue *q, int randomize){ q->head = q->tail = 0; /* create the queue */ q->size = 100; q->r = (rect *) malloc(q->size * sizeof(rect)); q->randomPt = 1; q->randomize = randomize;}/* Q_Checksize - check if the queue is full. If so, double the size */void Q_Checksize(rect_queue *q){ if (q->head == q->tail + 1 || !q->head && q->tail == q->size - 1) { /* if the queue is full */ q->r = (rect *) realloc(q->r, sizeof(rect) * q->size * 2); /* get a bigger queue */ if (q->tail < q->head) { memcpy(q->r + q->size, q->r, q->tail * sizeof(rect)); /* copy over any data that needs to be moved */ q->tail += q->size; } if (q->randomize && q->randomPt<q->head) { q->randomPt += q->size; } q->size *= 2; }}void Q_Print(rect_queue *q){ int i; i = q->head; while (i != q->tail) { fprintf(debug_file, "queue[%d] = (%d %d %d %d)\n", i, q->r[i].l, q->r[i].r, q->r[i].t, q->r[i].b); i++; if (i == q->size) i = 0; }}int Q_CheckValidity(rect_queue *q){ int i; i = q->head; while (i != q->tail) { if (q->r[i].l > 10000 || q->r[i].r > 10000 || q->r[i].t > 10000 || q->r[i].b > 10000 || q->r[i].length > 10000) { fprintf(debug_file, "Error in queue[%d]: (%d %d %d %d %d)\n", i, q->r[i].l, q->r[i].r, q->r[i].t, q->r[i].b, q->r[i].length); } if (++i == q->size) i = 0; } return 0;}/* Q_Enqueue - add a rectangle to the queue */void Q_Enqueue(rect_queue *q, rect *r)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -