Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,28 +1,46 @@
|
|||
/*****************************************************************
|
||||
* arbitrary vector length/type dot/scalar product *
|
||||
* as preprocessor macro with OpenMP SIMD and tree vectorize *
|
||||
* CFLAGS="-march=native -O3 -std=<c|gnu>23 *
|
||||
* -mfpmath=<your SIMD implementation> *
|
||||
* -ftree-vectorize -fopensmp-simd" *
|
||||
*****************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdalign.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
int dot_product(int *, int *, size_t);
|
||||
|
||||
int
|
||||
main(void)
|
||||
#define cnt(a) sizeof((a))/sizeof(typeof((a)[0]))
|
||||
#define dot(a,b,t,n,i) \
|
||||
({ \
|
||||
t dst = (t)i; \
|
||||
_Pragma("omp simd reduction(+:dst)") \
|
||||
for(size_t j = 0; j < MIN(MIN(cnt(a),cnt(b)),n); j++) \
|
||||
dst += (t)((a)[j] * (b)[j]); \
|
||||
dst; \
|
||||
})
|
||||
|
||||
/* default floating point scalar */
|
||||
typedef double flt;
|
||||
/* default dot products for length 3/4
|
||||
#define dot3(a,b) dot(a,b,flt,3,0)
|
||||
#define dot4(a,b) dot(a,b,flt,4,0)
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int a[3] = {1, 3, -5};
|
||||
int b[3] = {4, -2, -1};
|
||||
flt a[3] = { 1, 3, -5};
|
||||
flt b[3] = { 4, -2, -1};
|
||||
|
||||
printf("%d\n", dot_product(a, b, sizeof(a) / sizeof(a[0])));
|
||||
/**************************************************
|
||||
* cast output to double and use "%+e" allowing *
|
||||
* homogeneous formatted indented output of any *
|
||||
* numerical scalar return type of dot. *
|
||||
**************************************************/
|
||||
printf("%+e\n", (double)dot3(a, b));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
dot_product(int *a, int *b, size_t n)
|
||||
{
|
||||
int sum = 0;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
sum += a[i] * b[i];
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue