ssor.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // Copyright 2010 Intel Corporation
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include "RCCE.h"
  19. #include "applu_share.h"
  20. #include "applu_macros.h"
  21. void ssor(int niter) {
  22. //c---------------------------------------------------------------------
  23. //c local variables
  24. //c---------------------------------------------------------------------
  25. int i, j, k, m, mm, nn;
  26. int istep, one=1;
  27. double tmp;
  28. double tv[5*isiz1*isiz2];
  29. double wtime;
  30. //c---------------------------------------------------------------------
  31. //c begin pseudo-time stepping iterations
  32. //c---------------------------------------------------------------------
  33. tmp = 1.0 / ( omega * ( 2.0 - omega ) );
  34. //c---------------------------------------------------------------------
  35. //c initialize a,b,c,d to zero (guarantees that page tables have been
  36. //c formed, if applicable on given architecture, before timestepping).
  37. //c---------------------------------------------------------------------
  38. for (m=1; m<=isiz2; m++) {
  39. for (k=1; k<=isiz1; k++) {
  40. for (j=1; j<=5; j++) {
  41. for (i=1; i<=5; i++) {
  42. a(i,j,k,m) = 0.0;
  43. b(i,j,k,m) = 0.0;
  44. c(i,j,k,m) = 0.0;
  45. d(i,j,k,m) = 0.0;
  46. }
  47. }
  48. }
  49. }
  50. //c---------------------------------------------------------------------
  51. //c compute the steady-state residuals
  52. //c---------------------------------------------------------------------
  53. rhs();
  54. timer_clear(&one);
  55. timer_start(&one);
  56. //c---------------------------------------------------------------------
  57. //c the timestep loop
  58. //c---------------------------------------------------------------------
  59. for (istep = 1; istep<= niter; istep++) {
  60. rhs();
  61. if (id == 0) {
  62. if ( istep%20 == 0 || istep == itmax || istep == 1) {
  63. if (niter > 1) {printf(" Time step %4d\n", istep); fflush(0);}
  64. }
  65. }
  66. //c---------------------------------------------------------------------
  67. //c perform SSOR iteration
  68. //c---------------------------------------------------------------------
  69. for (k = 2; k<= nz - 1; k++) {
  70. for (j = jst; j<= jend; j++) {
  71. for (i = ist; i<= iend; i++) {
  72. for (m = 1; m<= 5; m++) {
  73. rsd(m,i,j,k) = dt * rsd(m,i,j,k);
  74. }
  75. }
  76. }
  77. }
  78. for (k = 2; k<= nz -1 ; k++) {
  79. //c---------------------------------------------------------------------
  80. //c form the lower triangular part of the jacobian matrix
  81. //c---------------------------------------------------------------------
  82. jacld(k);
  83. //c---------------------------------------------------------------------
  84. //c perform the lower triangular solution
  85. //c---------------------------------------------------------------------
  86. blts(k);
  87. }
  88. for (k = nz - 1; k>= 2; k--) {
  89. //c---------------------------------------------------------------------
  90. //c form the strictly upper triangular part of the jacobian matrix
  91. //c---------------------------------------------------------------------
  92. jacu(k);
  93. //c---------------------------------------------------------------------
  94. //c perform the upper triangular solution
  95. //c---------------------------------------------------------------------
  96. buts(k, tv);
  97. }
  98. //c---------------------------------------------------------------------
  99. //c update the variables
  100. //c---------------------------------------------------------------------
  101. for (k = 2; k<= nz-1; k++) {
  102. for (j = jst; j<= jend; j++) {
  103. for (i = ist; i<= iend; i++) {
  104. for (m = 1; m<= 5; m++) {
  105. u( m, i, j, k ) = u( m, i, j, k )
  106. + tmp * rsd( m, i, j, k );
  107. }
  108. }
  109. }
  110. }
  111. //c---------------------------------------------------------------------
  112. //c compute the steady-state residuals
  113. //c---------------------------------------------------------------------
  114. rhs();
  115. //c---------------------------------------------------------------------
  116. //c compute the max-norms of newton iteration residuals
  117. //c---------------------------------------------------------------------
  118. if (istep == itmax) {
  119. l2norm( isiz1, isiz2, isiz3, rsd, rsdnm );
  120. }
  121. }
  122. timer_stop(&one);
  123. wtime = timer_read(&one);
  124. RCCE_allreduce((char *)(&wtime), (char *)&maxtime, 1, RCCE_DOUBLE, RCCE_MAX, RCCE_COMM_WORLD);
  125. return;
  126. }