/* --------------------------------------------------------------- * MPI Mandelbrot Image Generation - C Version * FILE: mpi_mand.c * OTHER FILES: colormap.ras * DESCRIPTION: Mandelbrot image generation and display. Each processor * calculates the image pixels for a swath of rows in the output image. * These swaths of rows are then collected (using mpc_gather()) at a single * processor and then displayed on the screen, via X. * * AUTHOR: George Gusciora * LAST REVISED: George L. Gusciora (1/25/95) * --------------------------------------------------------------- */ #include "mpi.h" #include #include #include #include #include #include #include #define IMAGE_HEIGHT 512 /* Size of output image */ #define IMAGE_WIDTH 512 /* Size of output image */ #define TRUE 1 #define FALSE 0 #define DEST_PROCESSOR 0 /* Processor which will output the*/ /* image to the screen */ #define MAX_COUNT 100 /* max iterations for each image point */ #define MAX_SIZE 4.0 #define NCOLORS 249 /* X window stuff */ #define MYXEVENTS PointerMotionMask char *full_output_image; /* pointer to location of output image */ char *output_image_slice; /* block of rows in output image */ char anykey[1] ; int rasterfile_buf[8]; /* file I/O buffer */ int numtasks; /* Num processors in this job */ int taskid; /* ID number for each processor */ /*****************************************************************************/ /* The following are variables used to implment the X */ /* interface. No attempt is made to document this. */ /*****************************************************************************/ Colormap screencmap; int FOREGROUNDP=0; int BACKGROUNDP=1; XGCValues values; int screen,dplanes; Display *display; XImage *myimage; XWindowAttributes winfo; XSizeHints XSH; Window window; XSetWindowAttributes wattr; XEvent pmove; XColor Cmap[NCOLORS]; unsigned long cpixels[NCOLORS]; int cflag=0; GC linedefaultgc = NULL; unsigned char r[256], g[256], b[256]; int main(argc,argv) int argc; char *argv[]; { int allgrp; /* indicates all processors in this task */ int i, j, rc, count, nbuf[4]; float z_mag, zr, zi, cr, ci; float xinc, yinc, xstart, ystart, yend, xend, ymid, xmid; register double p_imag,p_real; register double z_imag,z_real,t_imag,t_real,z_size; FILE *fp, *fopen(); /* For file I/O */ int numtasks; /* Num processors in this job */ MPI_Status status; rc = MPI_Init(&argc,&argv); rc|= MPI_Comm_size(MPI_COMM_WORLD,&numtasks); rc|= MPI_Comm_rank(MPI_COMM_WORLD,&taskid); if (rc != MPI_SUCCESS) printf ("error initializing MPI and obtaining task ID information\n"); else printf ("mpi_mand MPI task ID = %d\n", taskid); /* DEST_PROCESSOR is the task which will be calling the X routines that display the image to the screen */ if (taskid == DEST_PROCESSOR) { /* Read colormap which will be used to display the image and initilize the X routines on the node which will display the image */ read_colormap(); initialize_x_stuff(); } /* Allocate space for images on each processor */ full_output_image = (char *) malloc(IMAGE_HEIGHT * IMAGE_WIDTH); output_image_slice = (char *) malloc((IMAGE_HEIGHT/numtasks) * IMAGE_WIDTH); /* Read the coordinates of this Mandelbrot exploration */ /* Parameters of the fractal space that are displayed */ yinc = 0.000001; xinc = 0.000001; ymid = 0.08405; xmid = -1.2540; ystart = ymid - (yinc * (float) (IMAGE_HEIGHT/2)); xstart = xmid - (xinc * (float) (IMAGE_WIDTH/2)); yend = ymid + (yinc * (float) (IMAGE_HEIGHT/2)); xend = xmid + (xinc * (float) (IMAGE_WIDTH/2)); if (taskid == DEST_PROCESSOR) { printf(" START MID END INC\n"); printf("\t%f\t%f\t%f\t\t%f\n", ystart, ymid, yend, yinc); printf("\t%f\t%f\t%f\t\t%f\n", xstart, xmid, xend, xinc); printf("\nGenerating image....Enter Ctrl-C to exit\n"); } for (i=0;i<(IMAGE_HEIGHT/numtasks);i++) /* For each row in swath */ { /* Determine imaginary coordinate value for this pixel */ p_imag = ystart + ((i + (taskid * (IMAGE_HEIGHT/numtasks))) * yinc); for (j=0;j1) { cflag=1; for(i=0;i