File: libmatrix.c

package info (click to toggle)
eztrace 2.2.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,012 kB
  • sloc: ansic: 37,703; sh: 1,246; cpp: 1,181; perl: 910; makefile: 738; fortran: 327; f90: 320; python: 124
file content (52 lines) | stat: -rw-r--r-- 1,089 bytes parent folder | download | duplicates (6)
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
/* -*- c-file-style: "GNU" -*- */
/*
 * Copyright (C) CNRS, INRIA, Université Bordeaux 1, Télécom SudParis
 * See COPYING in top-level directory.
 *
 *
 * libmatrix.c
 *
 *  Created on: 28 Sep. 2011
 *      Author: Damien Martin-Guillerez <damien.martin-guillerez@inria.fr>
 */

#include <stdlib.h>
#include "alacon.h"

double *matrix1;
double *matrix2;
int _h;
int _w;

int foo(int h, int w) {
  int i, j;
  _h = h;
  _w = w;
  matrix1 = (double*) malloc(sizeof(double) * h * w);
  matrix2 = (double*) malloc(sizeof(double) * h * w);
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      matrix1[i * w + j] = (i + 1) * (j + 1);
      matrix2[i + j * h] = (i + 1) * (j + 1);
    }
  }
  return (h + w);
}

int bar() {
  int i, j, k;
  double *result = (double*) malloc(sizeof(double) * _h * _h);
  for (i = 0; i < _h; i++) {
    for (j = 0; j < _h; j++) {
      result[i * _h + j] = 0;
      for (k = 0; k < _w; k++) {
        result[i * _h + j] += matrix1[i * _w + k] * matrix2[k * _h + j];
      }
    }
  }
  free(result);
  free(matrix1);
  free(matrix2);
  return 42;
}