Source Code Examples
Matrix Multiply – Naïve Version (Not Cache Friendly)
1 /* mm.c */
2
3 //
4 // My Matrix Multiplication app
5 //
6 // Uses standard triply-nested loop, not cache-friendly.
7 //
8
9 // Usage:
10 // mm [-?] [-n MatrixSize] [-t NumThreads]
11 //
12 #define LINUX
13 // #define WINDOWS
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <math.h>
19 #include <time.h>
20
21 #ifdef LINUX
22 #include <sys/time.h>
23 #endif
24
25 #include "pthread.h"
26
27
28 //
29 // Function prototypes:
30 //
31 double **MatrixMultiply(double** A, double** B, int N, int numthreads);
32 void _SequentialMM(double** C, double** A, double** B, int N);
33 void _ParallelMM(double** C, double** ...
Get Multicore Software Development Techniques now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.