// version using Java graphical display server over TCP/IP #include #include #include #include #include /* two values converge if their difference is less than EPSILON: */ // #define EPSILON 1e-5 #define EPSILON 1e-5 #define PI 3.1415927 /* N is size of NxN matrix, M is size of MxM quadrant, P is P*P workers */ #define N 288 #define M (2+N/2) #define P 2 // M is the dimension of each worker quadrant, which contains ghost vectors /**** for dynamically allocated, large contiguous arrays ****/ typedef double NROW[N+2]; NROW *Data; /* main data matrix - exists only on root process */ // first and last rows are for the initial, fixed values. typedef double QROW[M]; // M is already N/2 + 2 QROW *Q; /* one quadrant - needed by every process */ QROW *R; /* swap buffer */ /* macro to compute start address of quadrant in mesh */ /* These quadrants will overlap (2x2 mesh assumed) */ #define QUADRANT(DD,y,x) (DD[y*(N/2)]+(x*(N/2))) int mycoord[2]; /* stores mesh coordinates */ int locate[P][P]; /* used by master to locate workers in mesh */ #define YCORD mycoord[0] #define XCORD mycoord[1] #define NORTH 0 #define SOUTH 1 #define EAST 2 #define WEST 3 #define SND 0 #define RCV 1 MPI_Comm WORKERS, MESH; MPI_Datatype QUAD; // quadrant submatrix MPI_Datatype COLUMN; // one column in quadrant void master(); void worker(); void registerworkers(); /* used by master */ void registercoord(int,int); /* used by worker */ // number of iterations before a convergence vote and display update: int CVN = 40; /////////////////// void visualsetup(); // for graphics void visualize(NROW *); // for graphics void visualcleanup(); char* srvip; // ip address of Java graphics server //////////////////