-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmyblockmm_backup.c
87 lines (81 loc) · 2.32 KB
/
myblockmm_backup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xmmintrin.h>
#include <x86intrin.h>
#include <sys/time.h>
#include <pthread.h>
#include "myblockmm.h"
struct thread_info
{
int tid;
double **a, **b, **c;
int array_size;
int number_of_threads;
int n;
};
void *mythreaded_vector_blockmm(void *t);
char name[128];
char SID[128];
#define VECTOR_WIDTH 4
void my_threaded_vector_blockmm(double **a, double **b, double **c, int n, int ARRAY_SIZE, int number_of_threads)
{
int i=0;
pthread_t *thread;
struct thread_info *tinfo;
strcpy(name,"Ziliang Zhang");
strcpy(SID,"862186678");
thread = (pthread_t *)malloc(sizeof(pthread_t)*number_of_threads);
tinfo = (struct thread_info *)malloc(sizeof(struct thread_info)*number_of_threads);
for(i = 0 ; i < number_of_threads ; i++)
{
tinfo[i].a = a;
tinfo[i].b = b;
tinfo[i].c = c;
tinfo[i].tid = i;
tinfo[i].number_of_threads = number_of_threads;
tinfo[i].array_size = ARRAY_SIZE;
tinfo[i].n = n;
pthread_create(&thread[i], NULL, mythreaded_vector_blockmm, &tinfo[i]);
}
for(i = 0 ; i < number_of_threads ; i++)
pthread_join(thread[i], NULL);
return;
}
#define VECTOR_WIDTH 4
void *mythreaded_vector_blockmm(void *t)
{
int i,j,k, ii, jj, kk, x;
__m256d va, vb, vc;
struct thread_info tinfo = *(struct thread_info *)t;
int number_of_threads = tinfo.number_of_threads;
int tid = tinfo.tid;
double **a = tinfo.a;
double **b = tinfo.b;
double **c = tinfo.c;
int ARRAY_SIZE = tinfo.array_size;
int n = tinfo.n;
for(i = (ARRAY_SIZE/number_of_threads)*(tid); i < (ARRAY_SIZE/number_of_threads)*(tid+1); i+=ARRAY_SIZE/n)
{
for(j = 0; j < ARRAY_SIZE; j+=(ARRAY_SIZE/n))
{
for(k = 0; k < ARRAY_SIZE; k+=(ARRAY_SIZE/n))
{
for(ii = i; ii < i+(ARRAY_SIZE/n); ii++)
{
for(jj = j; jj < j+(ARRAY_SIZE/n); jj+=VECTOR_WIDTH)
{
vc = _mm256_load_pd(&c[ii][jj]);
for(kk = k; kk < k+(ARRAY_SIZE/n); kk++)
{
va = _mm256_broadcast_sd(&a[ii][kk]);
vb = _mm256_load_pd(&b[kk][jj]);
vc = _mm256_add_pd(vc,_mm256_mul_pd(va,vb));
}
_mm256_store_pd(&c[ii][jj],vc);
}
}
}
}
}
}