/* Sequential Mandelbrot program */ //http://www.coe.uncc.edu/~abw/parallel/par_prog/resources/mandelbrot.c //http://www.coe.uncc.edu/~abw/parallel/par_prog/resources/assign2.html #include #include #include #define X_RESN 800 /* x resolution */ #define Y_RESN 800 /* y resolution */ typedef struct complextype { float real, imag; } Compl; int main (int argc, char **argv) { FILE *fp, *fopen (); int size, rank; char filename[80]; //USE THIS FOR THE PARALLEL VERSION MPI_Init(&argc, &argv); fp = fopen("mandelpoints.txt","w"); //COMMENT OUT THIS LINE FOR THE //PARALLEL VERSION //UNCOMMENT THE SECTION BELOW FOR THE PARALLEL VERSION /* FOR THE PARALLEL VERSION, WRITING TO A FILE FROM EACH PROCESS CAN BE DONE: MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); sprintf(filename,"mandelpoints%d.txt", rank); fp = fopen(filename,"w"); */ /* Mandlebrot variables */ int i, j, k; Compl z, c; float lengthsq, temp; /* Calculate and draw points */ for(i=0; i < X_RESN; i++) for(j=0; j < Y_RESN; j++) { z.real = z.imag = 0.0; c.real = ((float) j - 400.0)/200.0; /* scale factors for 800 x 800 window */ c.imag = ((float) i - 400.0)/200.0; k = 0; do { /* iterate for pixel color */ temp = z.real*z.real - z.imag*z.imag + c.real; z.imag = 2.0*z.real*z.imag + c.imag; z.real = temp; lengthsq = z.real*z.real+z.imag*z.imag; k++; } while (lengthsq < 4.0 && k < 100); if (k == 100) { fprintf(fp,"%d %d\n", j, i); // I added this } } fclose(fp); //I added this /* Program Finished */ MPI_Finalize(); return 0; }