RCCE_shift.c.svn-base 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #define BUFSIZE 8
  18. int RCCE_APP(int argc, char **argv){
  19. int ID, ID_nb, ID_donor, nrounds, error, strlength;
  20. RCCE_FLAG flag_sent, flag_ack;
  21. double *cbuffer, *buffer, sum;
  22. char msg[RCCE_MAX_ERROR_STRING];
  23. RCCE_init(&argc, &argv);
  24. #ifdef TESTFLAGALLOC
  25. ID=0;
  26. while (!RCCE_flag_alloc(&flag_sent)) ID++;
  27. printf("Able to allocate %d flags\n", ID);
  28. exit(0);
  29. #endif
  30. ID = RCCE_ue();
  31. ID_nb = (ID+1)%RCCE_num_ues();
  32. ID_donor = (ID-1+RCCE_num_ues())%RCCE_num_ues();
  33. if (argc != 2) {
  34. if (ID==0) printf("Executable requires one parameter (number of rounds): %d\n",argc-1);
  35. return(1);
  36. }
  37. nrounds = atoi(*++argv);
  38. if (nrounds < 0) {
  39. if (ID==0) printf("Number of rounds should be non-negative: %d\n", nrounds);
  40. return(1);
  41. }
  42. /* allocate private memory and comm buffer space */
  43. buffer = (double *) malloc(BUFSIZE*sizeof(double));
  44. if (!buffer) printf("Mark 01: Failed to allocate private buffer on proc %d\n", ID);
  45. cbuffer = (double *) RCCE_malloc(BUFSIZE*sizeof(double));
  46. if (!buffer) printf("Mark 02:RCCE failed to allocate %d doubles on proc %d\n",
  47. BUFSIZE, ID);
  48. /* initialize buffer with UE-specific data */
  49. for (int i=0; i<BUFSIZE; i++) buffer[i] = (double)(ID+1+i);
  50. sum = 0.0;
  51. for (int i=0; i<BUFSIZE; i++) sum += buffer[i];
  52. printf("Initial sum on UE %03d equals %f\n", ID, sum);
  53. /* create and initialize flag variables */
  54. if (error=RCCE_flag_alloc(&flag_sent))
  55. printf("Mark 03a: Could not allocate flag_sent on %d, error=%d\n", ID, error);
  56. if (error=RCCE_flag_alloc(&flag_ack))
  57. printf("Mark 03b: Could not allocate flag_ack on %d, error=%d\n", ID, error);
  58. if(error=RCCE_flag_write(&flag_sent, RCCE_FLAG_UNSET, ID))
  59. printf("Mark 04: Could not initialize flag_sent on %d, error=%d\n", ID, error);
  60. if(error=RCCE_flag_write(&flag_ack, RCCE_FLAG_SET, ID_donor))
  61. printf("Mark 05: Could not initialize flag_ack on %d, error=%d\n", ID_donor, error);
  62. for (int round=0; round<nrounds; round++) {
  63. int size = BUFSIZE*sizeof(double);
  64. RCCE_wait_until(flag_ack, RCCE_FLAG_SET);
  65. RCCE_flag_write(&flag_ack, RCCE_FLAG_UNSET, ID);
  66. RCCE_put((t_vcharp)cbuffer, (t_vcharp)buffer, size, ID_nb);
  67. RCCE_flag_write(&flag_sent, RCCE_FLAG_SET, ID_nb);
  68. RCCE_wait_until(flag_sent, RCCE_FLAG_SET);
  69. RCCE_flag_write(&flag_sent, RCCE_FLAG_UNSET, ID);
  70. RCCE_get((t_vcharp)buffer, (t_vcharp)cbuffer, size, ID);
  71. RCCE_flag_write(&flag_ack, RCCE_FLAG_SET, ID_donor);
  72. }
  73. /* compute local sum */
  74. sum = 0.0;
  75. for (int i=0; i<BUFSIZE; i++) sum += buffer[i];
  76. printf("Final sum on UE %03d equals %f\n", ID, sum);
  77. RCCE_finalize();
  78. return(0);
  79. }