tutorial
来自「并行解法器,功能强大」· 代码 · 共 1,185 行 · 第 1/4 页
TXT
1,185 行
To make a grid size parameter that the user can input, one processormust read the input and then broadcast the value. Using the function AZ_broadcast(), add the lines necessary to have processor 0 (node name is given by proc_config[AZ_node]) read the grid size parameter from the user and broadcast the information to the other processors. See the AZ_broadcast() description in the Aztec User's Guide for more information.If the program is run and the value 7 is given as input (for a 7 x 7 grid), the resulting iteration output should approximately be: ******************************************************* ***** Preconditioned TFQMR solution ***** No preconditioning ***** No scaling ******************************************************* iter: 0 residual = 1.000000e+00 iter: 1 residual = 3.078276e-01 iter: 2 residual = 1.352989e-01 iter: 3 residual = 7.203379e-02 iter: 4 residual = 4.316646e-02 iter: 5 residual = 2.765714e-02 iter: 6 residual = 1.777434e-02 iter: 7 residual = 1.055632e-02 iter: 8 residual = 5.501200e-03 iter: 9 residual = 2.430743e-03 iter: 10 residual = 8.779539e-04 iter: 11 residual = 2.893932e-04 iter: 12 residual = 7.050597e-05 iter: 13 residual = 1.091404e-05 iter: 14 residual = 7.701444e-07---IMPORTANT: SAVE THIS PROGRAM IN THE FILE 'principal.c'.Problem 5: RIGHT hand side - 2D Poisson (n x n)=========Change the right hand side so that there is a '1' in each of the fourcorners of the grid and a '0' everywhere else.Note: The global right hand side vector 'B' needs to be distributed over the processors. That is, the specific element B[k] is stored on only 1 processor. The function AZ_transform() permutes the matrix such that the element B[k] must be stored in b[update_index[i]] on the processor for which there exists an i (0 <= i < N_update) such that update[i] = k.If this program is run using the value 7 as input, the resulting iterationoutput should approximately be: ******************************************************* ***** Preconditioned TFQMR solution ***** No preconditioning ***** No scaling ******************************************************* iter: 0 residual = 1.000000e+00 iter: 1 residual = 3.078276e-01 iter: 2 residual = 1.464818e-01 iter: 3 residual = 9.497719e-02 iter: 4 residual = 6.810138e-02 iter: 5 residual = 4.444184e-02 iter: 6 residual = 2.311353e-02 iter: 7 residual = 3.528172e-03 iter: 8 residual = 3.851591e-04 iter: 9 residual = 1.561198e-17---Problem 6: RIGHT hand side II - 2D Poisson (n x n)=========In some cases, we wish to initialize the right hand side vector at the same time that we initialize the matrix (ie. before AZ_transform()). Unfortunately, the array 'update_index' (used in the previous exercise) is only available after the AZ_transform() call. Instead of using thearray 'update_index', the global right hand side element B[k] can be stored as element tmp_b[i] on the processor for which there exists an i (0 <= i < N_update) such that update[i] = k. After AZ_transform() the tmp_b elements can be moved into their proper b[update_index[i]] location.Change the sample program so that the right hand side is initializedat the same time as the matrix. Then, after AZ_transform() is invokedpermute the right hand side so that it matches the matrix permutationdone in AZ_tranform().If this program is run using the value 7 as input, the resulting output should be the same as for Problem 5.Problem 7: EDITTING rhs - 2D Poisson (n x n)=========Modify the program so that after solving the system in Problem 6 itzeros out the 1's in the 2 right corners of the right hand side, andsolves the system again using the previous solution as an initial guess.Use the function AZ_find_index() to determine the location in 'update' of the points 'n-1' and 'n*n-1'.If this program is run using the value 7 as input, the resulting iteration output should approximately be: ******************************************************* ***** Preconditioned TFQMR solution ***** No preconditioning ***** No scaling ******************************************************* iter: 0 residual = 1.000000e+00 iter: 1 residual = 3.078276e-01 iter: 2 residual = 1.464818e-01 iter: 3 residual = 9.497719e-02 iter: 4 residual = 6.810138e-02 iter: 5 residual = 4.444184e-02 iter: 6 residual = 2.311353e-02 iter: 7 residual = 3.528172e-03 iter: 8 residual = 3.851591e-04 iter: 9 residual = 1.561198e-17 ******************************************************* ***** Preconditioned TFQMR solution ***** No preconditioning ***** No scaling ******************************************************* iter: 0 residual = 1.000000e+00 iter: 1 residual = 3.078276e-01 iter: 2 residual = 1.411253e-01 iter: 3 residual = 8.361324e-02 iter: 4 residual = 5.469282e-02 iter: 5 residual = 3.524117e-02 iter: 6 residual = 2.006837e-02 iter: 7 residual = 1.048266e-02 iter: 8 residual = 5.623542e-03 iter: 9 residual = 2.611812e-03 iter: 10 residual = 8.182422e-04 iter: 11 residual = 1.897014e-04 iter: 12 residual = 3.757968e-05 iter: 13 residual = 6.296418e-07Problem 8: EDITTING MATRIX - 2D Poisson (n x n)=========There might also arise cases where we wish to modify a matrix which has already been permuted by AZ_transform(). In this casewe must use 'update_index' and 'extern_index' to determine wherematrix values are stored.Write a new routine called 'post_create_matrix_row()' which overwrites theAZ_transform'ed matrix in between the 2 AZ_solve() calls in Problem 7.The matrix modification will only be applied to rows correspondingto grid points on the right boundary of the domain. Change the stencil at these boundary rows from -1 -1 4 to -1 1. -1Note: This exercise can be a bit tricky. The idea is to use AZ_find_index()on 'update' and/or on 'external' to find the location of the leftneighbor. The stencil value for this neighbor is to be kept as -1.For all other neighbors, the stencil value is changed to 0.IMPORTANT: AZ_find_index() can not be used on 'update_index' and'extern_index' as these are not in ascending order.If this program is run using the value 7 as input, the resulting iterationoutput should approximately be: ******************************************************* ***** Preconditioned TFQMR solution ***** No preconditioning ***** No scaling ******************************************************* iter: 0 residual = 1.000000e+00 iter: 1 residual = 3.078276e-01 iter: 2 residual = 1.464818e-01 iter: 3 residual = 9.497719e-02 iter: 4 residual = 6.810138e-02 iter: 5 residual = 4.444184e-02 iter: 6 residual = 2.311353e-02 iter: 7 residual = 3.528172e-03 iter: 8 residual = 3.851591e-04 iter: 9 residual = 1.561198e-17 ******************************************************* ***** Preconditioned TFQMR solution ***** No preconditioning ***** No scaling ******************************************************* iter: 0 residual = 1.000000e+00 iter: 1 residual = 1.462427e+00 iter: 2 residual = 1.574105e+00 iter: 3 residual = 1.270515e+00 iter: 4 residual = 1.094866e+00 iter: 5 residual = 1.077147e+00 iter: 6 residual = 1.038635e+00 iter: 7 residual = 8.276535e-01 iter: 8 residual = 6.019309e-01 iter: 9 residual = 4.498290e-01 iter: 10 residual = 1.996331e-01 iter: 11 residual = 6.072724e-02 iter: 12 residual = 2.070181e-02 iter: 13 residual = 8.442455e-04 iter: 14 residual = 5.841776e-04 iter: 15 residual = 3.081943e-04 iter: 16 residual = 7.862072e-05 iter: 17 residual = 3.015537e-05 iter: 18 residual = 1.175332e-06Problem 9: IRREGULAR grid - 2D Poisson-like (n lines)=========IMPORTANT: COPY THE FILE 'principal.c' INTO 'az_tutorial.c'. YOU MIGHT WANT TO SAVE 'az_tutorial.c' BEFORE DOING THIS.Change this program so that we can handle fairly arbitrary 2D regions.In particular, the user will input the number of horizontal lines inthe grid as the parameter 'n'. He will also supply two integer returning functions: left() and right(). left(i) returns the startingx value in the ith horizontal line. right(i) returns the ending x value in the ith horizontal line.For example, the functionsint left(int n){ return(0);} int right(int n){ if (n == 0) return(3); if (n == 1) return(2); if (n == 2) return(1); if (n == 3) return(2); else return(7);}used on a problem with 4 horizontal lines corresponds to the grid 9 10 11 7 8 4 5 6 0 1 2 3with Poisson matrix 4 -1 0 0 -1 0 0 0 0 0 0 0 -1 4 -1 0 0 -1 0 0 0 0 0 0 0 -1 4 -1 0 0 -1 0 0 0 0 0 0 0 -1 4 0 0 0 0 0 0 0 0 -1 0 0 0 4 -1 0 -1 0 0 0 0 0 -1 0 0 -1 4 -1 0 -1 0 0 0 0 0 -1 0 0 -1 4 0 0 0 0 0 0 0 0 0 -1 0 0 4 -1 -1 0 0 0 0 0 0 0 -1 0 -1 4 0 -1 0 0 0 0 0 0 0 0 -1 0 4 -1 0 0 0 0 0 0 0 0 0 -1 -1 4 -1 0 0 0 0 0 0 0 0 0 0 -1 4 Running this problem with the same initial guess (x = 0) and right hand side (b = e_1, where e_1 is the vector of all zeros except for the first element which is 1) should approximately produce the iteration output: ******************************************************* ***** Preconditioned TFQMR solution ***** No preconditioning ***** No scaling ******************************************************* iter: 0 residual = 1.000000e+00 iter: 1 residual = 3.078276e-01 iter: 2 residual = 1.212586e-01 iter: 3 residual = 3.382271e-02 iter: 4 residual = 5.095646e-03 iter: 5 residual = 1.262783e-03 iter: 6 residual = 1.029025e-04 iter: 7 residual = 1.146834e-05 iter: 8 residual = 6.605168e-09---Problem 10: 3D Poisson (n x n x n)==========IMPORTANT: COPY THE FILE 'principal.c' (created in Problem 4) INTO 'az_tutorial.c'. YOU MIGHT WANT TO SAVE 'az_tutorial.c' BEFORE DOING THIS.Change this program from a 2D Poisson approximation on the n x n square to a 3D Poisson approximation on the n x n x n cube. Run this problemwith the same initial guess (x = 0) and right hand side (B = e_1)NOTE: Remember to allocate enough memory for 'bindx' and 'val' to accomodate the 7 point stencil.If this program is run using the value 7 as input, the resulting iteration output should approximately be:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?