1 | /*************************************************************************/ |
---|
2 | /* */ |
---|
3 | /* Copyright (c) 1994 Stanford University */ |
---|
4 | /* */ |
---|
5 | /* All rights reserved. */ |
---|
6 | /* */ |
---|
7 | /* Permission is given to use, copy, and modify this software for any */ |
---|
8 | /* non-commercial purpose as long as this copyright notice is not */ |
---|
9 | /* removed. All other uses, including redistribution in whole or in */ |
---|
10 | /* part, are forbidden without prior written permission. */ |
---|
11 | /* */ |
---|
12 | /* This software is provided with absolutely no warranty and no */ |
---|
13 | /* support. */ |
---|
14 | /* */ |
---|
15 | /*************************************************************************/ |
---|
16 | |
---|
17 | #define MASTER 0 |
---|
18 | #define RED_ITER 0 |
---|
19 | #define BLACK_ITER 1 |
---|
20 | #define UP 0 |
---|
21 | #define DOWN 1 |
---|
22 | #define LEFT 2 |
---|
23 | #define RIGHT 3 |
---|
24 | #define UPLEFT 4 |
---|
25 | #define UPRIGHT 5 |
---|
26 | #define DOWNLEFT 6 |
---|
27 | #define DOWNRIGHT 7 |
---|
28 | #define PAGE_SIZE 4096 |
---|
29 | |
---|
30 | #include <user_barrier.h> |
---|
31 | #include <user_lock.h> |
---|
32 | |
---|
33 | // macro to use a shared TTY with the GIET_VM |
---|
34 | #define printf(...); { lock_acquire( &tty_lock ); \ |
---|
35 | giet_tty_printf(__VA_ARGS__); \ |
---|
36 | lock_release( &tty_lock ); } |
---|
37 | |
---|
38 | /////////////////////////////////////////////////////////////////////// |
---|
39 | // structures definition |
---|
40 | /////////////////////////////////////////////////////////////////////// |
---|
41 | |
---|
42 | struct multi_struct |
---|
43 | { |
---|
44 | double err_multi; |
---|
45 | }; |
---|
46 | |
---|
47 | struct global_struct |
---|
48 | { |
---|
49 | double psiai; |
---|
50 | double psibi; |
---|
51 | }; |
---|
52 | |
---|
53 | struct Global_Private |
---|
54 | { |
---|
55 | long * rel_num_x; // array[numlev] |
---|
56 | long * rel_num_y; // array[numlev] |
---|
57 | long * eist; // array[numlev] |
---|
58 | long * ejst; // array[numlev] |
---|
59 | long * oist; // array[numlev] |
---|
60 | long * ojst; // array[numlev] |
---|
61 | long * rlist; // array[numlev] |
---|
62 | long * rljst; // array[numlev] |
---|
63 | long * rlien; // array[numlev] |
---|
64 | long * rljen; // array[numlev] |
---|
65 | long rownum; |
---|
66 | long colnum; |
---|
67 | long neighbors[8]; |
---|
68 | long total_time; // total number of cyles in slave() |
---|
69 | long multi_time; // number of cycles in multig() |
---|
70 | long sync_time; // number of cycles waiting barriers |
---|
71 | long steps_time[10]; // number of cycles in phases of slave2() |
---|
72 | }; |
---|
73 | |
---|
74 | /////////////////////////////////////////////////////////////////////// |
---|
75 | // extern global variables |
---|
76 | /////////////////////////////////////////////////////////////////////// |
---|
77 | |
---|
78 | extern struct multi_struct * multi; |
---|
79 | extern struct global_struct * global; |
---|
80 | extern struct Global_Private ** gps; |
---|
81 | |
---|
82 | extern user_lock_t tty_lock; |
---|
83 | |
---|
84 | extern giet_sqt_barrier_t barrier; |
---|
85 | |
---|
86 | extern sqt_lock_t id_lock; |
---|
87 | extern sqt_lock_t psiai_lock; |
---|
88 | extern sqt_lock_t psibi_lock; |
---|
89 | extern sqt_lock_t done_lock; |
---|
90 | extern sqt_lock_t error_lock; |
---|
91 | extern sqt_lock_t bar_lock; |
---|
92 | |
---|
93 | extern double eig2; |
---|
94 | extern double ysca; |
---|
95 | extern long jmm1; |
---|
96 | extern const double pi; |
---|
97 | extern const double dt0; |
---|
98 | |
---|
99 | extern double **** psi; |
---|
100 | extern double **** psim; |
---|
101 | extern double *** psium; |
---|
102 | extern double *** psilm; |
---|
103 | extern double *** psib; |
---|
104 | extern double *** ga; |
---|
105 | extern double *** gb; |
---|
106 | extern double **** work1; |
---|
107 | extern double *** work2; |
---|
108 | extern double *** work3; |
---|
109 | extern double **** work4; |
---|
110 | extern double **** work5; |
---|
111 | extern double *** work6; |
---|
112 | extern double **** work7; |
---|
113 | extern double **** temparray; |
---|
114 | extern double *** tauz; |
---|
115 | extern double *** oldga; |
---|
116 | extern double *** oldgb; |
---|
117 | extern double * f; |
---|
118 | extern double **** q_multi; |
---|
119 | extern double **** rhs_multi; |
---|
120 | |
---|
121 | extern double factjacob; |
---|
122 | extern double factlap; |
---|
123 | |
---|
124 | extern double * i_int_coeff; |
---|
125 | extern double * j_int_coeff; |
---|
126 | |
---|
127 | extern long xprocs; |
---|
128 | extern long yprocs; |
---|
129 | |
---|
130 | extern long numlev; |
---|
131 | |
---|
132 | extern long * imx; |
---|
133 | extern long * jmx; |
---|
134 | extern double tolerance; |
---|
135 | extern double * lev_res; |
---|
136 | extern double * lev_tol; |
---|
137 | extern const double maxwork; |
---|
138 | extern long * xpts_per_proc; |
---|
139 | extern long * ypts_per_proc; |
---|
140 | extern long minlevel; |
---|
141 | extern const double outday0; |
---|
142 | extern const double outday1; |
---|
143 | extern const double outday2; |
---|
144 | extern const double outday3; |
---|
145 | |
---|
146 | extern long nprocs; |
---|
147 | |
---|
148 | extern const double h1; |
---|
149 | extern const double h3; |
---|
150 | extern const double h; |
---|
151 | extern const double lf; |
---|
152 | extern double res; |
---|
153 | extern double dtau; |
---|
154 | extern const double f0; |
---|
155 | extern const double beta; |
---|
156 | extern const double gpr; |
---|
157 | extern long oim; |
---|
158 | extern long im; |
---|
159 | extern long jm; |
---|
160 | |
---|
161 | /* |
---|
162 | * jacobcalc.C |
---|
163 | */ |
---|
164 | void jacobcalc (double ***x, double ***y, double ***z, long pid, long firstrow, long lastrow, long firstcol, long lastcol); |
---|
165 | |
---|
166 | /* |
---|
167 | * jacobcalc2.C |
---|
168 | */ |
---|
169 | void jacobcalc2 (double ****x, double ****y, double ****z, long psiindex, long pid, long firstrow, long lastrow, long firstcol, long lastcol); |
---|
170 | |
---|
171 | /* |
---|
172 | * laplacalc.C |
---|
173 | */ |
---|
174 | void laplacalc (long procid, double ****x, double ****z, long psiindex, long firstrow, long lastrow, long firstcol, long lastcol); |
---|
175 | |
---|
176 | /* |
---|
177 | * linkup.C |
---|
178 | */ |
---|
179 | void link_all (void); |
---|
180 | void linkup (double **row_ptr); |
---|
181 | void link_multi (void); |
---|
182 | |
---|
183 | /* |
---|
184 | * main.C |
---|
185 | */ |
---|
186 | long log_2 (long number); |
---|
187 | void printerr (char *s); |
---|
188 | |
---|
189 | /* |
---|
190 | * multi.C |
---|
191 | */ |
---|
192 | void multig (long my_id); |
---|
193 | void relax (long k, double *err, long color, long my_num); |
---|
194 | void rescal (long kf, long my_num); |
---|
195 | void intadd (long kc, long my_num); |
---|
196 | void putz (long k, long my_num); |
---|
197 | void copy_borders (long k, long pid); |
---|
198 | void copy_rhs_borders (long k, long procid); |
---|
199 | void copy_red (long k, long procid); |
---|
200 | void copy_black (long k, long procid); |
---|
201 | |
---|
202 | /* |
---|
203 | * slave1.C |
---|
204 | */ |
---|
205 | void slave (long *ptr_procid); |
---|
206 | |
---|
207 | /* |
---|
208 | * slave2.C |
---|
209 | */ |
---|
210 | void slave2 (long procid, long firstrow, long lastrow, long numrows, long firstcol, long lastcol, long numcols); |
---|
211 | |
---|
212 | /* |
---|
213 | * subblock.C |
---|
214 | */ |
---|
215 | void subblock (void); |
---|