| [6280cc6] | 1 | /* diffusion2d.c: parallel 2d-diffusion equation solver with constant boundaries
|
|---|
| [696be79] | 2 | * slicing matrix as a checker board.
|
|---|
| [6280cc6] | 3 | * To execute: mpicc diffusion2d.c ; mpiexec -n 4 ./a.out 2 2
|
|---|
| 4 | * To verify: civl verify diffusion2d.c
|
|---|
| [696be79] | 5 | */
|
|---|
| 6 | #include<stdio.h>
|
|---|
| 7 | #include<stdlib.h>
|
|---|
| 8 | #include<assert.h>
|
|---|
| 9 | #include<string.h>
|
|---|
| 10 | #include<mpi.h>
|
|---|
| 11 |
|
|---|
| 12 | /* Message tags */
|
|---|
| 13 | #define FROMLEFT 0
|
|---|
| 14 | #define FROMRIGHT 1
|
|---|
| 15 | #define FROMTOP 2
|
|---|
| 16 | #define FROMBOTTOM 3
|
|---|
| 17 | #define DATAPASS 4
|
|---|
| 18 | #define comm MPI_COMM_WORLD
|
|---|
| 19 |
|
|---|
| 20 | #ifdef _CIVL
|
|---|
| [a9b762c] | 21 | $input long NXB = 5; // nx upper bound
|
|---|
| 22 | $input long nx; // global number of columns in matrix
|
|---|
| [696be79] | 23 | $assume 1 <= nx && nx <= NXB;
|
|---|
| [a9b762c] | 24 | $input long NYB = 5; // ny upper bound
|
|---|
| 25 | $input long ny; // global number of rows of matrix
|
|---|
| [696be79] | 26 | $assume 1 <= ny && ny <= NYB;
|
|---|
| [a9b762c] | 27 | $input double u_init[ny+2][nx+2]; // initial value of temperatures, including boundaries
|
|---|
| 28 | $input double k; // constant coefficient
|
|---|
| [696be79] | 29 | $assume k > 0.0 && k < 0.5;
|
|---|
| [a9b762c] | 30 | $input int NSTEPSB = 3; // upper bound for nsteps
|
|---|
| 31 | $input int nsteps; // number of steps
|
|---|
| [696be79] | 32 | $assume 1<=nsteps && nsteps<=NSTEPSB;
|
|---|
| [a9b762c] | 33 | $input int wstep = 1; // write frame every this many time steps
|
|---|
| 34 | double oracle[nsteps][ny+2][nx+2]; // solution computed sequentially, done by proc 0 only
|
|---|
| 35 | $input int NPROCSXB; // upper bound for NPROCSX
|
|---|
| 36 | $input int NPROCSX = 2; // number of procs in x direction
|
|---|
| [bcf0c23] | 37 | $assume NPROCSX >= 1 && NPROCSX <= NPROCSXB;
|
|---|
| [a9b762c] | 38 | $input int NPROCSYB; // upper bound for NPROCSY
|
|---|
| 39 | $input int NPROCSY = 2; // number of procs in y direction
|
|---|
| [0d5d91b] | 40 | $assume NPROCSY >= 1 && NPROCSY <= NPROCSYB;
|
|---|
| [6280cc6] | 41 | $input int _NPROCS = NPROCSX * NPROCSY;
|
|---|
| [696be79] | 42 | #else
|
|---|
| [6280cc6] | 43 | long nx, ny;
|
|---|
| 44 | int nsteps, wstep;
|
|---|
| [696be79] | 45 | int NPROCSX, NPROCSY;
|
|---|
| [a9b762c] | 46 | double constTemp; // value of constant boundaries for test
|
|---|
| 47 | double initTemp; // value of initial temperature for test
|
|---|
| [696be79] | 48 | double k;
|
|---|
| 49 | #endif
|
|---|
| 50 |
|
|---|
| 51 | /* Global variables */
|
|---|
| [a9b762c] | 52 | int nprocs, rank;
|
|---|
| 53 | int left, right, top, bottom;// ranks of neighbors
|
|---|
| 54 | int nxl; // local dimension of x
|
|---|
| 55 | int nyl; // local dimension of y
|
|---|
| 56 | long firstCol; // index of the first column in global array
|
|---|
| 57 | long firstRow; // index of the first row in global array
|
|---|
| 58 | /* dynamically-allocated 2d array of doubles specifying state of local
|
|---|
| 59 | * grid in current time step. Dimensions are u_curr[nyl+2][nxl+2].
|
|---|
| 60 | */
|
|---|
| [696be79] | 61 | double ** u_curr;
|
|---|
| [a9b762c] | 62 | /* dynamically-allocated 2d array of doubles specifying state of local
|
|---|
| 63 | * grid in next time step. Dimensions are u_next[nyl+2][nxl+2].
|
|---|
| 64 | */
|
|---|
| [696be79] | 65 | double ** u_next;
|
|---|
| [a9b762c] | 66 | /* dynamically-allocated 1d temporary buffer. Length is recvbuf[nxl+1]
|
|---|
| 67 | */
|
|---|
| 68 | double * recvbuf;
|
|---|
| [696be79] | 69 |
|
|---|
| [a9b762c] | 70 | /* The processes are arranged geometrically as follows for the case
|
|---|
| 71 | * NPROCSX = 3:
|
|---|
| [6280cc6] | 72 | * row 0: 0 1 2
|
|---|
| 73 | * row 1: 3 4 5
|
|---|
| [a9b762c] | 74 | * ...
|
|---|
| 75 | * This function computes the global index of the first column
|
|---|
| 76 | * owned by the process of the given rank. rank must be in the
|
|---|
| 77 | * range [0, _NPROCS-1]. The result will in the range [0, nx-1].
|
|---|
| 78 | */
|
|---|
| [6280cc6] | 79 | long firstColForProc(int rank) {
|
|---|
| 80 | long tmp = (rank - (rank / NPROCSX)*NPROCSX)*nx;
|
|---|
| 81 |
|
|---|
| 82 | return tmp/NPROCSX;
|
|---|
| [696be79] | 83 | }
|
|---|
| 84 |
|
|---|
| [a9b762c] | 85 | /* This function computes the global index of the first row owned by
|
|---|
| 86 | the process of the given rank. rank must be in the range[0,
|
|---|
| 87 | _NPROCS-1]. The result will in the range [0, ny-1]. */
|
|---|
| [6280cc6] | 88 | long firstRowForProc(int rank) {
|
|---|
| 89 | long tmp = ((rank / NPROCSX)*ny);
|
|---|
| 90 |
|
|---|
| 91 | return tmp/NPROCSY;
|
|---|
| [696be79] | 92 | }
|
|---|
| 93 |
|
|---|
| [a9b762c] | 94 | /* Computes the number of columns owned by the process. The result
|
|---|
| 95 | will be in the range [0, nx]. */
|
|---|
| [696be79] | 96 | int countColForProc(int rank) {
|
|---|
| [6280cc6] | 97 | long a = firstColForProc(rank);
|
|---|
| 98 | long b;
|
|---|
| [696be79] | 99 |
|
|---|
| [a9b762c] | 100 | if ((rank / NPROCSX) == ((rank+1) / NPROCSX))
|
|---|
| [696be79] | 101 | b = firstColForProc(rank+1);
|
|---|
| 102 | else
|
|---|
| 103 | b = nx;
|
|---|
| 104 | return b - a;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| [a9b762c] | 107 | /* Computes the number of rows owned by the process. The result
|
|---|
| 108 | will be in the range [0, ny]. */
|
|---|
| [696be79] | 109 | int countRowForProc(int rank) {
|
|---|
| [6280cc6] | 110 | long a = firstRowForProc(rank);
|
|---|
| 111 | long b = firstRowForProc(rank+NPROCSX);
|
|---|
| [696be79] | 112 |
|
|---|
| 113 | return b - a;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | /* Get the owner process of the given cell */
|
|---|
| [6280cc6] | 117 | int OWNER(long col, long row) {
|
|---|
| 118 | long tmp = ((NPROCSY * (row+1))-1);
|
|---|
| 119 | int procRow = tmp / ny;
|
|---|
| 120 | int procCol;
|
|---|
| 121 |
|
|---|
| 122 | tmp = ((col + 1) * NPROCSX - 1);
|
|---|
| 123 | procCol = tmp / nx;
|
|---|
| 124 | tmp = procRow * NPROCSX;
|
|---|
| 125 | return tmp + procCol;
|
|---|
| [696be79] | 126 | }
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| [6280cc6] | 129 | /* initialize all data values owned by each process */
|
|---|
| 130 | void initData() {
|
|---|
| [696be79] | 131 | #ifdef _CIVL
|
|---|
| [a9b762c] | 132 | // Data is initialized with totally unconstrained values
|
|---|
| 133 | // for verification.
|
|---|
| 134 | // set the vertical boundary cells:
|
|---|
| 135 | if (left == MPI_PROC_NULL)
|
|---|
| 136 | for (int i=0; i<nyl+2; i++)
|
|---|
| [6280cc6] | 137 | u_next[i][0] = u_curr[i][0] = u_init[i + firstRow][0];
|
|---|
| [a9b762c] | 138 | if (right == MPI_PROC_NULL)
|
|---|
| 139 | for (int i=0; i<nyl+2; i++)
|
|---|
| [6280cc6] | 140 | u_next[i][nxl+1] = u_curr[i][nxl+1] = u_init[i + firstRow][nx+1];
|
|---|
| [a9b762c] | 141 | // set the horizontal boundary cells:
|
|---|
| 142 | if (top == MPI_PROC_NULL)
|
|---|
| 143 | for (int i=0; i<nxl+2; i++)
|
|---|
| [6280cc6] | 144 | u_next[0][i] = u_curr[0][i] = u_init[0][i + firstCol];
|
|---|
| [a9b762c] | 145 | if (bottom == MPI_PROC_NULL)
|
|---|
| 146 | for (int i=0; i<nxl+2; i++)
|
|---|
| [6280cc6] | 147 | u_next[nyl+1][i] = u_curr[nyl+1][i] = u_init[ny+1][i + firstCol];
|
|---|
| [a9b762c] | 148 | for (int i=1; i<nyl+1; i++)
|
|---|
| [6280cc6] | 149 | memcpy(&u_curr[i][1], &u_init[firstRow + i][firstCol + 1], nxl * sizeof(double));
|
|---|
| 150 | #else
|
|---|
| [a9b762c] | 151 | // All boundary cells are set to the same value constTemp.
|
|---|
| 152 | // All cells in the interior region are set to the same value
|
|---|
| 153 | // initTemp.
|
|---|
| 154 | for (int i=0; i < nyl+2; i++)
|
|---|
| 155 | for (int j=0; j < nxl+2; j++)
|
|---|
| 156 | if (i == 0 || j == 0 || i == nyl+1 || j == nxl+1)
|
|---|
| 157 | u_next[i][j] = u_curr[i][j] = constTemp;
|
|---|
| [6280cc6] | 158 | else
|
|---|
| [a9b762c] | 159 | u_curr[i][j] = initTemp;
|
|---|
| [696be79] | 160 | #endif
|
|---|
| [6280cc6] | 161 | }
|
|---|
| [696be79] | 162 |
|
|---|
| [a9b762c] | 163 | /* Initialize all global variables, allocate memory spaces for
|
|---|
| 164 | * pointers and proc 0 will do a sequential run. The results of the
|
|---|
| 165 | * sequential run will be used to compare with parallel run later. */
|
|---|
| [696be79] | 166 | void initialization(int argc, char * argv[]) {
|
|---|
| 167 | #ifndef _CIVL
|
|---|
| 168 | nsteps = 300;
|
|---|
| 169 | wstep = 5;
|
|---|
| 170 | nx = 15;
|
|---|
| 171 | ny = 15;
|
|---|
| [a9b762c] | 172 | if (argc != 3) {
|
|---|
| 173 | printf("Usage: mpiexec -n NPROCS diffusion2d NPROCSX NPROCSY\n"
|
|---|
| 174 | " NPROCSX: number of processes in x direction\n"
|
|---|
| 175 | " NPROCSY: number of processes in y direction\n"
|
|---|
| 176 | " NPROCS: the product of NPROCSX and NPROCSY\n");
|
|---|
| 177 | exit(1);
|
|---|
| [696be79] | 178 | }
|
|---|
| 179 | NPROCSX = atoi(argv[1]);
|
|---|
| 180 | NPROCSY = atoi(argv[2]);
|
|---|
| [a9b762c] | 181 | assert(NPROCSX * NPROCSY == nprocs);
|
|---|
| [696be79] | 182 | constTemp = 0.0;
|
|---|
| 183 | initTemp = 100.0;
|
|---|
| 184 | k = 0.13;
|
|---|
| 185 | #endif
|
|---|
| [a9b762c] | 186 | printf("Diffusion2d with k=%f, nx=%ld, ny=%ld, nsteps=%d, wstep=%d\n",
|
|---|
| 187 | k, nx, ny, nsteps, wstep);
|
|---|
| [696be79] | 188 | nxl = countColForProc(rank);
|
|---|
| 189 | nyl = countRowForProc(rank);
|
|---|
| [a9b762c] | 190 | if (rank == 0)
|
|---|
| 191 | recvbuf = (double *)malloc((nxl + 1) * sizeof(double));
|
|---|
| [696be79] | 192 | u_curr = (double **)malloc((nyl + 2) * sizeof(double *));
|
|---|
| 193 | assert(u_curr);
|
|---|
| 194 | u_next = (double **)malloc((nyl + 2) * sizeof(double *));
|
|---|
| 195 | assert(u_next);
|
|---|
| [a9b762c] | 196 | for (int i=0; i < nyl + 2; i++){
|
|---|
| [696be79] | 197 | u_curr[i] = (double *)malloc((nxl + 2) * sizeof(double));
|
|---|
| 198 | assert(u_curr[i]);
|
|---|
| 199 | u_next[i] = (double *)malloc((nxl + 2) * sizeof(double));
|
|---|
| 200 | assert(u_next[i]);
|
|---|
| 201 | }
|
|---|
| 202 | firstCol = firstColForProc(rank);
|
|---|
| 203 | firstRow = firstRowForProc(rank);
|
|---|
| 204 | // computes neighbors
|
|---|
| [a9b762c] | 205 | if (firstCol != 0)
|
|---|
| [696be79] | 206 | left = OWNER(firstCol - 1, firstRow);
|
|---|
| 207 | else
|
|---|
| 208 | left = MPI_PROC_NULL;
|
|---|
| [a9b762c] | 209 | if (firstRow != 0)
|
|---|
| [696be79] | 210 | top = OWNER(firstCol, firstRow - 1);
|
|---|
| 211 | else
|
|---|
| 212 | top = MPI_PROC_NULL;
|
|---|
| [a9b762c] | 213 | if (firstCol + nxl < nx)
|
|---|
| [696be79] | 214 | right = OWNER(firstCol + nxl, firstRow);
|
|---|
| 215 | else
|
|---|
| 216 | right = MPI_PROC_NULL;
|
|---|
| [a9b762c] | 217 | if (firstRow + nyl < ny)
|
|---|
| [696be79] | 218 | bottom = OWNER(firstCol, firstRow + nyl);
|
|---|
| 219 | else
|
|---|
| 220 | bottom = MPI_PROC_NULL;
|
|---|
| 221 | #ifdef _CIVL
|
|---|
| [a9b762c] | 222 | /* In CIVL mode process with rank 0 will be responsible for
|
|---|
| 223 | * computing the diffusion2d equation sequentially such that the
|
|---|
| 224 | * results can be used to compare with the ones of parallel run. */
|
|---|
| 225 | if (rank == 0) {
|
|---|
| 226 | for (long i = 0; i < ny + 2; i++)
|
|---|
| 227 | for (long j = 0; j < nx + 2; j++)
|
|---|
| 228 | oracle[0][i][j] = u_init[i][j];
|
|---|
| 229 | for (int t=1; t < nsteps; t++)
|
|---|
| 230 | for (long i = 0; i < ny + 2; i++)
|
|---|
| 231 | for (long j = 0; j < nx + 2; j++)
|
|---|
| 232 | if (i==0 || j==0 || i == ny + 1 || j == nx + 1)
|
|---|
| 233 | oracle[t][i][j] = oracle[t-1][i][j];
|
|---|
| 234 | else
|
|---|
| 235 | oracle[t][i][j] = oracle[t-1][i][j] +
|
|---|
| 236 | k*(oracle[t-1][i+1][j] + oracle[t-1][i-1][j] +
|
|---|
| 237 | oracle[t-1][i][j+1] + oracle[t-1][i][j-1] -
|
|---|
| 238 | 4*oracle[t-1][i][j]);
|
|---|
| [696be79] | 239 | }
|
|---|
| 240 | #endif
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| [a9b762c] | 243 | /* Update local cells owned by process */
|
|---|
| [696be79] | 244 | void update() {
|
|---|
| 245 | double **tmp;
|
|---|
| 246 |
|
|---|
| [a9b762c] | 247 | for (int i = 1; i < nyl + 1; i++)
|
|---|
| 248 | for (int j = 1; j < nxl + 1; j++) {
|
|---|
| [696be79] | 249 | u_next[i][j] = u_curr[i][j] +
|
|---|
| [a9b762c] | 250 | k*(u_curr[i+1][j] + u_curr[i-1][j] +
|
|---|
| 251 | u_curr[i][j+1] + u_curr[i][j-1] - 4*u_curr[i][j]);
|
|---|
| [696be79] | 252 | }
|
|---|
| [a9b762c] | 253 | // swap two pointers
|
|---|
| [696be79] | 254 | tmp = u_curr;
|
|---|
| 255 | u_curr = u_next;
|
|---|
| 256 | u_next = tmp;
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| [a9b762c] | 259 | /* Exchange ghost cells between proceeses */
|
|---|
| [696be79] | 260 | void exchange() {
|
|---|
| 261 | double sendbuf[nyl];
|
|---|
| 262 | double recvbuf[nyl];
|
|---|
| 263 |
|
|---|
| [a9b762c] | 264 | // sends top border row, receives into bottom ghost cell row
|
|---|
| [696be79] | 265 | MPI_Sendrecv(&u_curr[1][1], nxl, MPI_DOUBLE, top, FROMBOTTOM, &u_curr[nyl+1][1], nxl,
|
|---|
| [a9b762c] | 266 | MPI_DOUBLE, bottom, FROMBOTTOM, comm, MPI_STATUS_IGNORE);
|
|---|
| 267 | // sends bottom border row, receives into top ghost cell row
|
|---|
| [696be79] | 268 | MPI_Sendrecv(&u_curr[nyl][1], nxl, MPI_DOUBLE, bottom, FROMTOP, &u_curr[0][1], nxl,
|
|---|
| [a9b762c] | 269 | MPI_DOUBLE, top, FROMTOP, comm, MPI_STATUS_IGNORE);
|
|---|
| 270 | // sends left border column, receives into temporary buffer
|
|---|
| 271 | for (int i = 0; i < nyl; i++) sendbuf[i] = u_curr[i+1][1];
|
|---|
| [696be79] | 272 | MPI_Sendrecv(sendbuf, nyl, MPI_DOUBLE, left, FROMRIGHT, recvbuf, nyl,
|
|---|
| [a9b762c] | 273 | MPI_DOUBLE, right, FROMRIGHT, comm, MPI_STATUS_IGNORE);
|
|---|
| 274 | // copies temporary buffer into right ghost cell column
|
|---|
| 275 | if (right != MPI_PROC_NULL)
|
|---|
| 276 | for (int i = 0; i < nyl; i++) u_curr[i+1][nxl+1] = recvbuf[i];
|
|---|
| 277 | // sends right border column, receives into temporary buffer
|
|---|
| 278 | for (int i = 0; i < nyl; i++) sendbuf[i] = u_curr[i+1][nxl];
|
|---|
| [696be79] | 279 | MPI_Sendrecv(sendbuf, nyl, MPI_DOUBLE, right, FROMLEFT, recvbuf, nyl,
|
|---|
| [a9b762c] | 280 | MPI_DOUBLE, left, FROMLEFT, comm, MPI_STATUS_IGNORE);
|
|---|
| 281 | // copies temporary buffer into left ghost cell column
|
|---|
| 282 | if (left != MPI_PROC_NULL)
|
|---|
| 283 | for (int i = 0; i < nyl; i++) u_curr[i+1][0] = recvbuf[i];
|
|---|
| [696be79] | 284 | }
|
|---|
| 285 |
|
|---|
| [a9b762c] | 286 | /* Helper function for write_frame(int). In CIVL mode, it takes the
|
|---|
| 287 | index of the first column, the number of columns owned by the
|
|---|
| 288 | process and the index of current row to locate the corresponding
|
|---|
| 289 | cell in oracle and compare it with the given cell's value computed
|
|---|
| 290 | in parallel */
|
|---|
| [6280cc6] | 291 | void printData(int time, int firstCol, int nxl, int currRow, double * buf) {
|
|---|
| [a9b762c] | 292 | for (int i=0; i<nxl; i++) {
|
|---|
| [6280cc6] | 293 | printf("%6.2f", *(buf + i));
|
|---|
| [696be79] | 294 | #ifdef _CIVL
|
|---|
| [6280cc6] | 295 | $assert(*(buf + i) == oracle[time][currRow + 1][firstCol + i + 1]) : \
|
|---|
| [696be79] | 296 | "Error: disagreement at time %d position [%d][%d]: saw %lf, expected %lf", \
|
|---|
| [6280cc6] | 297 | time, currRow, firstCol + i,
|
|---|
| 298 | *(buf + i), oracle[time][currRow + 1][firstCol + i + 1];
|
|---|
| [696be79] | 299 | #endif
|
|---|
| 300 | }
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| [a9b762c] | 303 | /* Print the computed matrix at the given time step all processes
|
|---|
| 304 | * should send their local data to process rank 0 which is responsible
|
|---|
| 305 | * for printing */
|
|---|
| [696be79] | 306 | void write_frame(int time) {
|
|---|
| [a9b762c] | 307 | // sends data row by row
|
|---|
| 308 | if (rank != 0) {
|
|---|
| 309 | for (int i=0; i<nyl; i++)
|
|---|
| 310 | MPI_Send(&u_curr[i+1][1], nxl, MPI_DOUBLE, 0, DATAPASS, comm);
|
|---|
| 311 | } else {
|
|---|
| [696be79] | 312 | printf("\n-------------------- time step:%d --------------------\n", time);
|
|---|
| [a9b762c] | 313 | for (int i=0; i < NPROCSY; i++) {
|
|---|
| [6280cc6] | 314 | int numRows = countRowForProc(i*NPROCSX);
|
|---|
| 315 |
|
|---|
| [a9b762c] | 316 | for (int j=0; j < numRows; j++) {
|
|---|
| 317 | for (int k=0; k < NPROCSX; k++) {
|
|---|
| [43ea051] | 318 | int curr_rank = i*NPROCSX + k;
|
|---|
| [a9b762c] | 319 |
|
|---|
| 320 | if (curr_rank!=0) {
|
|---|
| 321 | int senderx = firstColForProc(curr_rank);
|
|---|
| 322 | int sendery = firstRowForProc(curr_rank);
|
|---|
| 323 | int senderNxl = countColForProc(curr_rank);
|
|---|
| 324 |
|
|---|
| 325 | MPI_Recv(recvbuf, senderNxl, MPI_DOUBLE, curr_rank, DATAPASS, comm, MPI_STATUS_IGNORE);
|
|---|
| 326 | printData(time, senderx, senderNxl, sendery+j, recvbuf);
|
|---|
| 327 | } else {
|
|---|
| 328 | printData(time, firstCol, nxl, firstRow+j, &u_curr[j+1][1]);
|
|---|
| 329 | }
|
|---|
| 330 | }
|
|---|
| 331 | printf("\n");
|
|---|
| [696be79] | 332 | }
|
|---|
| 333 | }
|
|---|
| [6280cc6] | 334 | }
|
|---|
| [696be79] | 335 | }
|
|---|
| 336 |
|
|---|
| 337 | int main(int argc, char * argv[]) {
|
|---|
| 338 | int i,j;
|
|---|
| 339 |
|
|---|
| 340 | #ifdef _CIVL
|
|---|
| 341 | // elaborating nx, ny, NPROCSX and NPROCSY...
|
|---|
| 342 | elaborate(nx);
|
|---|
| 343 | elaborate(ny);
|
|---|
| 344 | elaborate(NPROCSX);
|
|---|
| 345 | elaborate(NPROCSY);
|
|---|
| 346 | #endif
|
|---|
| 347 | MPI_Init(&argc, &argv);
|
|---|
| 348 | MPI_Comm_rank(comm, &rank);
|
|---|
| 349 | MPI_Comm_size(comm, &nprocs);
|
|---|
| 350 | initialization(argc, argv);
|
|---|
| [6280cc6] | 351 | initData();
|
|---|
| [a9b762c] | 352 | for (i=0; i<nsteps; i++) {
|
|---|
| 353 | if (nxl != 0 && nyl != 0) {
|
|---|
| 354 | if (i%wstep == 0)
|
|---|
| 355 | write_frame(i);
|
|---|
| [696be79] | 356 | exchange();
|
|---|
| 357 | update();
|
|---|
| 358 | }
|
|---|
| 359 | }
|
|---|
| [a9b762c] | 360 | for (i=0; i<nyl+2; i++) {
|
|---|
| [696be79] | 361 | free(u_curr[i]);
|
|---|
| 362 | free(u_next[i]);
|
|---|
| 363 | }
|
|---|
| 364 | free(u_curr);
|
|---|
| 365 | free(u_next);
|
|---|
| [a9b762c] | 366 | if (rank == 0)
|
|---|
| 367 | free(recvbuf);
|
|---|
| [696be79] | 368 | return 0;
|
|---|
| 369 | }
|
|---|