home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume21
/
cloops
/
part01
/
sumo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-25
|
2KB
|
82 lines
/*
* This file is part of the Livermore Loops transliteration into C.
* Copyright (C) 1991 by Martin Fouts
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "types.h"
Float sumo(v,n)
Float v[];
int n;
{
Float s = 0.0;
Int k;
for (k = 0; k < n; k++)
s += (Float)(k+1) * v[k];
return(s);
}
#define V2(i,j) v[j + (i * d2)]
#define V3(i,j,k) v[k + (j * d3) + (i * d3 * d2)]
Float sumo2(v,n1,n2,d1,d2)
Float v[];
int n1, n2;
int d1, d2;
{
Float s = 0.0;
Float l = 1.0;
Int point = n1 * n2;
Int added = 0;
Int i, j;
for (j = 0; j < d2; j++) {
for (i = 0; i < d1; i++) {
s += l * V2(i,j);
l++;
if (++added >= point)
return(s);
}
}
return(s);
}
Float sumo3(v,n1,n2,n3,d1,d2,d3)
Float v[];
int n1, n2, n3;
int d1, d2, d3;
{
Float s = 0.0;
Float l = 1.0;
Int point = n1 * n2 * n3;
Int added = 0;
Int i, j, k;
for (k = 0; k < d3; k++) {
for (j = 0; j < d2; j++) {
for (i = 0; i < d1; i++) {
s += l * V3(i,j,k);
l++;
if (++added >= point)
return(s);
}
}
}
return(s);
}