home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume21 / cloops / part01 / sumo.c < prev    next >
C/C++ Source or Header  |  1991-07-25  |  2KB  |  82 lines

  1. /*
  2.  * This file is part of the Livermore Loops transliteration into C.
  3.  * Copyright (C) 1991 by Martin Fouts
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 1, or (at your option)
  8.  * any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include "types.h"
  21.  
  22. Float sumo(v,n)
  23. Float v[];
  24. int n;
  25. {
  26.   Float s = 0.0;
  27.   Int k;
  28.   for (k = 0; k < n; k++)
  29.     s += (Float)(k+1) * v[k];
  30.   return(s);
  31. }
  32.  
  33. #define V2(i,j) v[j + (i * d2)]
  34. #define V3(i,j,k) v[k + (j * d3) + (i * d3 * d2)]
  35.  
  36. Float sumo2(v,n1,n2,d1,d2)
  37. Float v[];
  38. int n1, n2;
  39. int d1, d2;
  40. {
  41.   Float s = 0.0;
  42.   Float l = 1.0;
  43.   Int point = n1 * n2;
  44.   Int added = 0;
  45.   Int i, j;
  46.  
  47.   for (j = 0; j < d2; j++) {
  48.     for (i = 0; i < d1; i++) {
  49.       s += l * V2(i,j);
  50.       l++;
  51.       if (++added >= point)
  52.     return(s);
  53.     }
  54.   }
  55.   return(s);
  56. }
  57.  
  58. Float sumo3(v,n1,n2,n3,d1,d2,d3)
  59. Float v[];
  60. int n1, n2, n3;
  61. int d1, d2, d3;
  62. {
  63.   Float s = 0.0;
  64.   Float l = 1.0;
  65.   Int point = n1 * n2 * n3;
  66.   Int added = 0;
  67.   Int i, j, k;
  68.  
  69.   for (k = 0; k < d3; k++) {
  70.     for (j = 0; j < d2; j++) {
  71.       for (i = 0; i < d1; i++) {
  72.     s += l * V3(i,j,k);
  73.     l++;
  74.     if (++added >= point)
  75.       return(s);
  76.       }
  77.     }
  78.   }
  79.   return(s);
  80. }
  81.  
  82.