l2norm.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 <math.h>
  17. #include "RCCE.h"
  18. #include "applu_share.h"
  19. #include "applu_macros.h"
  20. #include "applu_protos.h"
  21. #define v(m,i,j,k) v[m-1+5*((i+1)+(ldx+4)*((j+1)+(ldy+4)*(k-1)))]
  22. #define sum(m) sum[m-1]
  23. #define dummy(m) dummy[m-1]
  24. void l2norm(int ldx, int ldy, int ldz, double *v, double *sum ) {
  25. //c to compute the l2-norm of vector v.
  26. int i, j, k, m;
  27. double dummy[5];
  28. for (m=1; m<=5; m++) dummy(m) = 0.0;
  29. for (k=2; k<=nz0-1; k++)
  30. for (j=jst; j<=jend; j++)
  31. for (i=ist; i<=iend; i++)
  32. for (m=1; m<=5; m++)
  33. dummy(m)+= v(m,i,j,k) * v(m,i,j,k);
  34. //c compute the global sum of individual contributions to dot product.
  35. RCCE_allreduce( (char*)dummy, (char*)sum, 5, RCCE_DOUBLE, RCCE_SUM, RCCE_COMM_WORLD);
  36. for (m=1; m<=5; m++)
  37. sum(m) = sqrt ( sum(m) / ( (nx0-2)*(ny0-2)*(nz0-2) ) );
  38. return;
  39. }