-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpartition.c
39 lines (32 loc) · 988 Bytes
/
partition.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
#include "utils.h"
#include "partition.h"
#include <assert.h>
#include <stdio.h>
void partition(
int n, int num_tiles, int tlsz, int *restrict p)
{
// Partition into tiles of size tlsz. The first tile may be smaller.
for (int i = 1; i < num_tiles; i++)
p[i] = n - (num_tiles - i) * tlsz;
// Pad so that the size computes p[i + 1] - p[i].
p[0] = 0;
p[num_tiles] = n;
}
void partition_matrix(
const double *restrict A, int ldA,
const partitioning_t *restrict p,
double ***restrict A_tiles)
{
// Extract row and column partitioning.
const int *first_row = p->first_row;
const int *first_col = p->first_col;
const int num_tile_rows = p->num_tile_rows;
const int num_tile_cols = p->num_tile_cols;
#define A(i,j) A[(i) + (j) * ldA]
for (int i = 0; i < num_tile_rows; i++) {
for (int j = 0; j < num_tile_cols; j++) {
A_tiles[i][j] = &A(first_row[i], first_col[j]);
}
}
#undef A
}