RCCE_simshift.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <string.h>
  17. #include <stdio.h>
  18. #include "RCCE.h"
  19. #define BUFSIZE 16
  20. int RCCE_APP(int argc, char **argv){
  21. int ID, ID_nb, ID_donor, nrounds, error, strlength, phase, c, i, round;
  22. double *buffer, *buffer2, sum;
  23. char msg[RCCE_MAX_ERROR_STRING];
  24. if(RCCE_init(&argc, &argv)) {
  25. printf("Error in RCCE_init; bailing\n");
  26. exit(1);
  27. }
  28. ID = RCCE_ue();
  29. ID_nb = (ID+1)%RCCE_num_ues();
  30. ID_donor = (ID-1+RCCE_num_ues())%RCCE_num_ues();
  31. if (argc != 2) {
  32. if (ID==0) printf("Executable requires one parameter (number of rounds): %d\n",argc-1);
  33. return(1);
  34. }
  35. nrounds = atoi(*++argv);
  36. if (nrounds < 0) {
  37. if (ID==0) printf("Number of rounds should be non-negative: %d\n", nrounds);
  38. return(1);
  39. }
  40. /* allocate private memory */
  41. buffer = (double *) malloc(2*BUFSIZE*sizeof(double));
  42. if (!buffer) printf("Mark 01: Failed to allocate private buffer on proc %d\n", ID);
  43. buffer2 = buffer + BUFSIZE;
  44. /* initialize buffer with UE-specific data */
  45. for (i=0; i<BUFSIZE; i++) buffer[i] = (double)(ID+1);
  46. sum = 0.0;
  47. for (i=0; i<BUFSIZE; i++) sum += buffer[i];
  48. printf("Initial sum on UE %03d equals %f\n", ID, sum); fflush(0);
  49. for (round=0; round<nrounds; round++) {
  50. /* do the circular shift of data */
  51. for (phase = 0; phase<2; phase++) {
  52. if ((ID+phase)%2) RCCE_send((char *)buffer, BUFSIZE*sizeof(double), ID_nb);
  53. if (!((ID+phase)%2)) RCCE_recv((char *)buffer2, BUFSIZE*sizeof(double), ID_donor);
  54. }
  55. memcpy(buffer, buffer2, BUFSIZE*sizeof(double));
  56. }
  57. /* compute local sum */
  58. sum = 0.0;
  59. for (i=0; i<BUFSIZE; i++) sum += buffer[i];
  60. printf("Final sum on UE %03d equals %f\n", ID, sum); fflush(0);
  61. RCCE_finalize();
  62. return(0);
  63. }