/* Simplified version of laplacian program: The matrix will be divided one-dimensionally among P*P processors. There will still be one coordinating processor, which means that the workers must have their own communicator. Each process must still communicate with its neighbors via asynchronous communication and manage its "ghost vectors". The size of the total matrix is the same (288+2). */ #include #include #include #include #include #include "mpe_graphics.h" #include "mpe.h" /******** #3D graphical library *********/ #include "threed.c" /* two values converge if their difference is less than EPSILON: */ // #define EPSILON 1e-5 #define EPSILON 1e-5 #define PI 3.1415927 #define GRAPHICS 1 /* N is size of NxN matrix, and M is size of Mx(N+2) */ #define N 288 #define M 74 #define P 2 /**** for dynamically allocated, large contiguous arrays ****/ typedef double NROW[N+2]; NROW *Data; /* main data matrix - exists only on root process */ /**** for dynamically allocated slice ****/ NROW *Q; /* one slice, including ghosts, needed by everyone */ NROW *R; /* swap matrix (Q and R will flip back and forth */ /* macro to compute start address of overlapping slices in matrix */ #define SLICE(DD,y) (DD[y*(N/(P*P))]) int mrank; /* rank of worker process within WORKERS communicator*/ int locate[P*P]; /* used by master process to determine rank of worker*/ #define NORTH 0 #define SOUTH 1 #define SND 0 #define RCV 1 #define QACTIVE 0 #define RACTIVE 1 MPI_Comm WORKERS; // WORKERS COMMUNICATOR void master(); void worker(); void registerworkers(); /* used by master */ void registercoord(int); /* used by worker */ void setup(); // for graphics void visualize(NROW *); // for graphics /* For graphics */ MPE_XGraph graph; MPE_Color mcolor[9] = {MPE_RED,MPE_BLUE,MPE_GREEN,MPE_YELLOW,MPE_BROWN,MPE_ORANGE,MPE_GRAY,MPE_PINK,MPE_BLACK}; int mousesynch = 0; // mouse click between frames flag // number of iterations before a convergence vote and display update: int CVN = 40;