-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix_add.c
More file actions
52 lines (38 loc) · 780 Bytes
/
matrix_add.c
File metadata and controls
52 lines (38 loc) · 780 Bytes
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
#include "stdio.h"
#include "sys/types.h"
#include "sys/times.h"
#include "ulocks.h"
#include "sys/param.h"
#include <time.h>
#define N 800
int A[N][N], B[N][N], C[N][N];
int nprocs=8;
void slaveproc();
void populate_matrices();
int main(void)
{
int i, j;
for(i=0; i<N; i++)
for(j=0; j<N; j++)
A[i][j]=j;
for(i=0; i<N; i++)
for(j=0; j<N; j++)
B[i][j]=1;
m_set_procs(nprocs);
clock_t begin, end;
begin=clock();
m_fork(slaveproc);
end=clock();
printf("Time used: %f\n", (double)(end-begin)/CLOCKS_PER_SEC);
m_kill_procs();
}
void slaveproc()
{
int i, nproc, id, j;
nproc = m_get_numprocs();
id = m_get_myid();
int step= N/nproc;
for(i=id*step; i<(id+1)*step; i++)
for(j=0; j<N; j++)
C[i][j]=A[i][j]+B[i][j];
}