diff options
| author | Leo Chan <leochanj@live.unc.edu> | 2020-10-22 01:53:21 -0400 |
|---|---|---|
| committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-22 01:56:35 -0400 |
| commit | d17b33131c14864bd1eae275f49a3f148e21cf29 (patch) | |
| tree | 0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/benchmarks/stitch/src/c/dist2.c | |
| parent | 601ed25a4c5b66cb75315832c15613a727db2c26 (diff) | |
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to:
- Use libextra to loop as realtime jobs
- Preallocate memory before starting their main computation
- Accept input via stdin instead of via argc
Does not include the SD-VBS matlab code.
Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/benchmarks/stitch/src/c/dist2.c')
| -rw-r--r-- | SD-VBS/benchmarks/stitch/src/c/dist2.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/stitch/src/c/dist2.c b/SD-VBS/benchmarks/stitch/src/c/dist2.c new file mode 100644 index 0000000..d76fcb2 --- /dev/null +++ b/SD-VBS/benchmarks/stitch/src/c/dist2.c | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include "stitch.h" | ||
| 6 | |||
| 7 | F2D* dist2(I2D* x, F2D* c) | ||
| 8 | { | ||
| 9 | int ndata, dimx, ncentres, dimc, i, j, k; | ||
| 10 | F2D *n2, *t1, *t2; | ||
| 11 | float temp; | ||
| 12 | F2D *s1, *s2, *ctrans; | ||
| 13 | F2D *mult1, *mult2, *mult3; | ||
| 14 | |||
| 15 | ndata = x->height; | ||
| 16 | dimx = x->width; | ||
| 17 | |||
| 18 | ncentres = c->height; | ||
| 19 | dimc = c->width; | ||
| 20 | |||
| 21 | if(dimx != dimc) | ||
| 22 | return NULL; | ||
| 23 | |||
| 24 | s1 = fSetArray(ncentres, 1, 1); | ||
| 25 | s2 = fSetArray(ndata, 1, 1); | ||
| 26 | t1 = fMallocHandle(1, x->height); | ||
| 27 | |||
| 28 | for(j=0; j<t1->width; j++) | ||
| 29 | { | ||
| 30 | temp = 0; | ||
| 31 | for(i=0; i<t1->height; i++) | ||
| 32 | { | ||
| 33 | temp += subsref(x,j,i) * subsref(x,j,i); | ||
| 34 | } | ||
| 35 | |||
| 36 | asubsref(t1,j) = temp; | ||
| 37 | } | ||
| 38 | |||
| 39 | mult1 = fMtimes(s1, t1); | ||
| 40 | t2 = fMallocHandle(1, c->height); | ||
| 41 | |||
| 42 | for(j=0; j<t2->width; j++) | ||
| 43 | { | ||
| 44 | temp = 0; | ||
| 45 | for(i=0; i<t2->height; i++) | ||
| 46 | { | ||
| 47 | temp += subsref(c,j,i) * subsref(c,j,i); | ||
| 48 | } | ||
| 49 | |||
| 50 | asubsref(t2,j) = temp; | ||
| 51 | } | ||
| 52 | |||
| 53 | mult2 = fMtimes(s2, t2); | ||
| 54 | ctrans = fTranspose(c); | ||
| 55 | mult3 = ifMtimes(x, ctrans); | ||
| 56 | |||
| 57 | for(i=0; i<(mult3->height * mult3->width); i++) | ||
| 58 | asubsref(mult3,i) = asubsref(mult3,i) * 2; | ||
| 59 | |||
| 60 | free(t1); | ||
| 61 | free(t2); | ||
| 62 | free(s1); | ||
| 63 | free(s2); | ||
| 64 | free(ctrans); | ||
| 65 | |||
| 66 | n2 = fMallocHandle(ndata, ncentres); | ||
| 67 | for(i=0; i<(ndata*ncentres); i++) | ||
| 68 | asubsref(n2,i) = asubsref(mult1,i) + asubsref(mult2,i) - asubsref(mult3,i); | ||
| 69 | |||
| 70 | free(mult1); | ||
| 71 | free(mult2); | ||
| 72 | free(mult3); | ||
| 73 | |||
| 74 | return n2; | ||
| 75 | |||
| 76 | } | ||
