source: soft/giet_vm/applications/rosenfeld/src-par/mca_matrix_dist.c

Last change on this file was 821, checked in by meunier, 8 years ago
  • Added several versions of rosenfeld: { SLOW, FAST } x { FEATURES, NO_FEATURES }
  • Added native linux compilation support
  • Added a script to check results natively
  • Started to refactor nrc code
File size: 2.8 KB
Line 
1/* -------------------- */
2/* --- matrix_dist.c -- */
3/* -------------------- */
4
5// Copyright (c) 2015-2016 Lionel Lacassagne, All Rights Reserved
6// Laboratoire d'Informatique de Paris 6 - LIP6
7// Universite Pierre et Marie Curie UPMC / CNRS
8
9
10#include <stdio.h>
11#include <stdbool.h> // C99
12#include <stdlib.h>
13#include <string.h>
14#include <malloc.h>
15
16#include "nrc_os_config.h"
17#include "nrc.h"
18
19
20#include "mca_matrix_dist.h"
21
22// ==================================================================
23// === fonctions allocation memoire =================================
24// ==================================================================
25
26// ------------------------------------------------------
27uint32 ** dist_ui32matrix(int i0, int i1, int j0, int j1)
28// ------------------------------------------------------
29{
30    int i;
31    int nrow = i1 - i0 + 1;
32    int ncol = j1 - j0 + 1;
33    uint32 ** m;
34   
35    // allocate pointers to rows
36    m = (uint32 **) malloc((nrow + 2) * sizeof(uint32 *));
37    if (!m) {
38        nrerror("allocation failure 1 in dist_ui32matrix()");
39    }
40    m -= i0;
41    m += 1;
42   
43    // allocate rows and set pointers to them
44    m[i0] = (uint32 *) malloc((nrow * ncol + 1) * sizeof(uint32));
45    if (!m[i0]) {
46        nrerror("allocation failure 2 in dist_ui32matrix()");
47    }
48    m[i0] -= j0;
49   
50    for (i = i0 + 1; i <= i1; i++) {
51        m[i] = m[i - 1] + ncol;
52    }
53   
54    // make borders to point to first and last lines
55    m[i0 - 1] = m[i0];
56    m[i1 + 1] = m[i1];
57   
58    return m;
59}
60
61#if TARGET_OS == GIETVM
62// ---------------------------------------------------------------------------
63uint32 ** remote_dist_ui32matrix(int i0, int i1, int j0, int j1, int x, int y)
64// ---------------------------------------------------------------------------
65{
66    int i;
67    int nrow = i1 - i0 + 1;
68    int ncol = j1 - j0 + 1;
69    uint32 ** m;
70   
71    // allocate pointers to rows
72    m = (uint32 **) remote_malloc((nrow + 2) * sizeof(uint32 *), x, y);
73    if (!m) {
74        nrerror("allocation failure 1 in dist_ui32matrix()");
75    }
76    m -= i0;
77    m += 1;
78   
79    // allocate rows and set pointers to them
80    m[i0] = (uint32 *) remote_malloc((nrow * ncol + 1) * sizeof(uint32), x, y);
81    if (!m[i0]) {
82        nrerror("allocation failure 2 in dist_ui32matrix()");
83    }
84    m[i0] -= j0;
85   
86    for (i = i0 + 1; i <= i1; i++) {
87        m[i] = m[i - 1] + ncol;
88    }
89   
90    // make borders to point to first and last lines
91    m[i0 - 1] = m[i0];
92    m[i1 + 1] = m[i1];
93   
94    return m;
95}
96#endif
97
98
99
100// -------------------------------------------------------------------
101void free_dist_ui32matrix(uint32 ** m, int i0, int i1, int j0, int j1)
102// -------------------------------------------------------------------
103{
104    free(m[i0] + j0);
105    free(m + i0 - 1);
106}
107
Note: See TracBrowser for help on using the repository browser.