exchange_4.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <stdio.h>
  19. #include "directions.h"
  20. #include "applu_share.h"
  21. #include "applu_macros.h"
  22. #define g(i,j) g[i+(isiz2+2)*(j)]
  23. #define h(i,j) h[i+(isiz2+2)*(j)]
  24. #define COMM_SIZE 1024
  25. void exchange_4(double *g, double *h,
  26. int ibeg, int ifin1, int jbeg, int jfin1) {
  27. int i, j;
  28. size_t chunk;
  29. double bufin[COMM_SIZE], bufout[COMM_SIZE];
  30. int ny2 = ny + 2;
  31. //c---------------------------------------------------------------------
  32. //c communicate in the east and west directions
  33. //c---------------------------------------------------------------------
  34. //c---------------------------------------------------------------------
  35. //c receive from east
  36. //c---------------------------------------------------------------------
  37. if (jfin1 == ny) {
  38. RCCE_recv((char*)bufin, 2*nx*sizeof(double), east);
  39. for (int ib=0, i=1; i<=nx; i++) {
  40. g(i,ny+1) = bufin[ib++];
  41. h(i,ny+1) = bufin[ib++];
  42. }
  43. }
  44. //c---------------------------------------------------------------------
  45. //c send west
  46. //c---------------------------------------------------------------------
  47. if (jbeg == 1) {
  48. for (int ib=0,i=1; i<=nx; i++) {
  49. bufout[ib++] = g(i,1);
  50. bufout[ib++] = h(i,1);
  51. }
  52. RCCE_send((char*)bufout, 2*nx*sizeof(double), west);
  53. }
  54. //c---------------------------------------------------------------------
  55. //c communicate in the south and north directions
  56. //c---------------------------------------------------------------------
  57. //c---------------------------------------------------------------------
  58. //c receive from south
  59. //c---------------------------------------------------------------------
  60. if (ifin1 == nx) {
  61. RCCE_recv((char*)bufin, 2*ny2*sizeof(double), south);
  62. for (int ib=0,j=0; j<=ny+1; j++) {
  63. g(nx+1,j) = bufin[ib++];
  64. h(nx+1,j) = bufin[ib++];
  65. }
  66. }
  67. //c---------------------------------------------------------------------
  68. //c send north
  69. //c---------------------------------------------------------------------
  70. if (ibeg == 1) {
  71. for (int ib=0,j=0; j<=ny+1; j++) {
  72. bufout[ib++] = g(1,j);
  73. bufout[ib++] = h(1,j);
  74. }
  75. RCCE_send((char*)bufout, 2*ny2*sizeof(double), north);
  76. }
  77. return;
  78. }