File: testmultrect.c

package info (click to toggle)
ga 5.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,472 kB
  • sloc: ansic: 192,963; fortran: 53,761; f90: 11,218; cpp: 5,784; makefile: 2,248; sh: 1,945; python: 1,734; perl: 534; csh: 134; asm: 106
file content (114 lines) | stat: -rw-r--r-- 2,240 bytes parent folder | download | duplicates (5)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
 * testmultrect.c
 * Test rectangular matrix multiplication.
 *
 * Nawab Ali <nawab.ali@pnl.gov>
 */
#if HAVE_CONFIG_H
#   include "config.h"
#endif

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "ga.h"
#include "macdecls.h"
#include "mp3.h"

#define NDIMS 2                 /* 2-dimensional matrices */

#define HEAP  4000000
#define STACK 4000000

int m = 2;
int k = 3;
int n = 4;
int g_a, g_b, g_c;              /* GA handles for matrices A, B, and C */

int mr_create_matrices(void);
int mr_cleanup(void);


int main(int argc, char **argv) {
    int ret, nprocs;
    int me, heap, stack;

    /* Initialize message passing and GA */
    MP_INIT(argc,argv);
    GA_INIT(argc,argv);

    me = GA_Nodeid();
    nprocs = GA_Nnodes();
    heap = HEAP/nprocs;
    stack = STACK/nprocs;

    if (!MA_init(C_DBL, stack, heap)) {
        GA_Error("MA_init failed", stack+heap);
    }

    /* Create the matrices A, B, C */
    ret = mr_create_matrices();

    GA_Print(g_a);
    GA_Print(g_b);
    GA_Print(g_c);

    /* C = A x B */
    GA_Dgemm('N', 'N', m, n, k, 1.0, g_a, g_b, 0.0, g_c);

    /* Clean up */
    ret = mr_cleanup();

    if (me == 0)
      printf("All tests successful\n");

    GA_Terminate();
    MP_FINALIZE();

    return 0;
}

int mr_create_matrices(void) {
    double val_a = 10.0;
    double val_b = 20.0;
    int ret, dims[NDIMS];

    /* Create a 2-dimensional matrix A[m][k] */
    dims[0] = m;
    dims[1] = k;

    g_a = GA_Create_handle();
    GA_Set_array_name(g_a, "Matrix A");
    GA_Set_data(g_a, NDIMS, dims, C_DBL);
    ret = GA_Allocate(g_a);
    GA_Fill(g_a, &val_a);

    /* Create a 2-dimensional matrix B[k][n] */
    dims[0] = k;
    dims[1] = n;

    g_b = GA_Create_handle();
    GA_Set_array_name(g_b, "Matrix B");
    GA_Set_data(g_b, NDIMS, dims, C_DBL);
    ret = GA_Allocate(g_b);
    GA_Fill(g_b, &val_b);

    /* Create a 2-dimensional matrix C[m][n] */
    dims[0] = m;
    dims[1] = n;

    g_c = GA_Create_handle();
    GA_Set_array_name(g_c, "Matrix C");
    GA_Set_data(g_c, NDIMS, dims, C_DBL);
    ret = GA_Allocate(g_c);
    GA_Zero(g_c);

    return 0;
}

int mr_cleanup(void) {
    GA_Destroy(g_a);
    GA_Destroy(g_b);
    GA_Destroy(g_c);
    return 0;
}