exchange_1.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 "RCCE.h"
  17. #include <stdlib.h>
  18. #include "directions.h"
  19. #include "applu_share.h"
  20. #include "applu_macros.h"
  21. #define g(m,i,j,k) g[m-1+5*((i+1)+(isiz1+4)*((j+1)+(isiz2+4)*(k-1)))]
  22. void exchange_1(double *g, int k, int iex) {
  23. int i, j;
  24. size_t chunk;
  25. int error, len;
  26. char msg[200];
  27. double bufin[5*(isiz1+isiz2)], bufout[5*(isiz1+isiz2)];
  28. if( iex == 0 ) {
  29. if( north != -1 ) {
  30. RCCE_recv((char*)bufin, 5*(jend-jst+1)*sizeof(double), north);
  31. for (int ib=0,j=jst; j<=jend; j++) {
  32. g(1,0,j,k) = bufin[ib++];
  33. g(2,0,j,k) = bufin[ib++];
  34. g(3,0,j,k) = bufin[ib++];
  35. g(4,0,j,k) = bufin[ib++];
  36. g(5,0,j,k) = bufin[ib++];
  37. }
  38. }
  39. if( west != -1 ) {
  40. RCCE_recv((char*)bufin, 5*(iend-ist+1)*sizeof(double), west);
  41. for (int ib=0,i=ist; i<=iend; i++) {
  42. g(1,i,0,k) = bufin[ib++];
  43. g(2,i,0,k) = bufin[ib++];
  44. g(3,i,0,k) = bufin[ib++];
  45. g(4,i,0,k) = bufin[ib++];
  46. g(5,i,0,k) = bufin[ib++];
  47. }
  48. }
  49. }
  50. else if( iex == 1 ) {
  51. if( south != -1 ) {
  52. RCCE_recv((char*)bufin, 5*(jend-jst+1)*sizeof(double), south);
  53. for (int ib=0,j=jst; j<=jend; j++) {
  54. g(1,nx+1,j,k) = bufin[ib++];
  55. g(2,nx+1,j,k) = bufin[ib++];
  56. g(3,nx+1,j,k) = bufin[ib++];
  57. g(4,nx+1,j,k) = bufin[ib++];
  58. g(5,nx+1,j,k) = bufin[ib++];
  59. }
  60. }
  61. if( east != -1 ) {
  62. RCCE_recv((char*)bufin, 5*(iend-ist+1)*sizeof(double), east);
  63. for (int ib=0,i=ist; i<=iend; i++) {
  64. g(1,i,ny+1,k) = bufin[ib++];
  65. g(2,i,ny+1,k) = bufin[ib++];
  66. g(3,i,ny+1,k) = bufin[ib++];
  67. g(4,i,ny+1,k) = bufin[ib++];
  68. g(5,i,ny+1,k) = bufin[ib++];
  69. }
  70. }
  71. }
  72. else if( iex == 2 ) {
  73. if( south != -1 ) {
  74. for (int ib=0,j=jst; j<=jend; j++) {
  75. bufout[ib++] = g(1,nx,j,k);
  76. bufout[ib++] = g(2,nx,j,k);
  77. bufout[ib++] = g(3,nx,j,k);
  78. bufout[ib++] = g(4,nx,j,k);
  79. bufout[ib++] = g(5,nx,j,k);
  80. }
  81. RCCE_send((char*)bufout, 5*(jend-jst+1)*sizeof(double), south);
  82. }
  83. if( east != -1 ) {
  84. for (int ib=0,i=ist; i<=iend; i++) {
  85. bufout[ib++] = g(1,i,ny,k);
  86. bufout[ib++] = g(2,i,ny,k);
  87. bufout[ib++] = g(3,i,ny,k);
  88. bufout[ib++] = g(4,i,ny,k);
  89. bufout[ib++] = g(5,i,ny,k);
  90. }
  91. RCCE_send((char*)bufout, 5*(iend-ist+1)*sizeof(double), east);
  92. }
  93. }
  94. else {
  95. if( north != -1 ) {
  96. for (int ib=0,j=jst; j<=jend; j++) {
  97. bufout[ib++] = g(1,1,j,k);
  98. bufout[ib++] = g(2,1,j,k);
  99. bufout[ib++] = g(3,1,j,k);
  100. bufout[ib++] = g(4,1,j,k);
  101. bufout[ib++] = g(5,1,j,k);
  102. }
  103. RCCE_send((char*)bufout, 5*(jend-jst+1)*sizeof(double), north);
  104. }
  105. if( west != -1 ) {
  106. for (int ib=0,i=ist; i<=iend; i++) {
  107. bufout[ib++] = g(1,i,1,k);
  108. bufout[ib++] = g(2,i,1,k);
  109. bufout[ib++] = g(3,i,1,k);
  110. bufout[ib++] = g(4,i,1,k);
  111. bufout[ib++] = g(5,i,1,k);
  112. }
  113. RCCE_send((char*)bufout, 5*(iend-ist+1)*sizeof(double), west);
  114. }
  115. }
  116. return;
  117. }