File: MatMulMPI.c

package info (click to toggle)
spooles 2.2-16
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,760 kB
  • sloc: ansic: 146,836; sh: 7,571; csh: 3,615; makefile: 1,970; perl: 74
file content (212 lines) | stat: -rw-r--r-- 6,158 bytes parent folder | download | duplicates (7)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*  MatMulMPI.c  */

#include "../BridgeMPI.h"

#define MYDEBUG 1

#if MYDEBUG > 0
static int count_MatMul = 0 ;
static double time_MatMul = 0.0 ;
#endif

/*--------------------------------------------------------------------*/
/*
   -------------------------------------------------------------
   purpose --- to compute a matrix-vector multiply y[] = C * x[]
     where C is the identity, A or B (depending on *pprbtype).

   *pnrows -- # of rows in x[]
   *pncols -- # of columns in x[]
   *pprbtype -- problem type
      *pprbtype = 1 --> vibration problem, matrix is A
      *pprbtype = 2 --> buckling problem, matrix is B
      *pprbtype = 3 --> matrix is identity, y[] = x[]

   created -- 98aug11, cca & jcp
   -------------------------------------------------------------
*/
void 
MatMulMPI ( 
   int      *pnrows, 
   int      *pncols, 
   double   x[], 
   double   y[],
   int      *pprbtype,
   void     *data
) {
BridgeMPI   *bridge = (BridgeMPI *) data ; 
int         ncols, nent, nrows ;
#if MYDEBUG > 0
double   t1, t2 ;
count_MatMul++ ;
MARKTIME(t1) ;
if ( bridge->myid == 0 ) {
   fprintf(stdout, "\n (%d) MatMulMPI()", count_MatMul) ;
   fflush(stdout) ;
}
#endif
#if MYDEBUG > 1
fprintf(bridge->msgFile, "\n (%d) MatMulMPI()", count_MatMul) ;
fflush(bridge->msgFile) ;
#endif

nrows = *pnrows ;
ncols = *pncols ;
nent  = nrows*ncols ;
if ( *pprbtype == 3 ) {
/*
    --------------------------
    ... matrix is the identity
    --------------------------
*/
   if ( x == NULL ) {
      fprintf(stderr, "\n\n fatal error in MatMulMPI, y <-- x, x is NULL") ;
      exit(-1) ;
   }
   if ( y == NULL ) {
      fprintf(stderr, "\n\n fatal error in MatMulMPI, y <-- x, y is NULL") ;
      exit(-1) ;
   }
   DVcopy(nent, y, x) ;
   return;
} else {
   DenseMtx    *Xloc = bridge->Xloc, *Yloc = bridge->Yloc ;
   double      alpha[2] = {1.0, 0.0} ;
   FILE        *msgFile = bridge->msgFile ;
   int         msglvl = bridge->msglvl, n, nmyowned, tag = 0 ;
   int         *list, *owned ;
   int         stats[4] ;
   MPI_Comm    comm = bridge->comm ;
/*
   -----------------------------------------------
   if the matrices are in global coordinates
   (i.e., this is the first matrix-vector multiply
    following a factorization) then
   map the matrix into local coordinates
   -----------------------------------------------
*/
   if ( bridge->msglvl > 1 ) {
      fprintf(bridge->msgFile, 
              "\n\n inside MatMulMPI, nrow = %d, ncol = %d",
              nrows, ncols) ;
   }
   if ( msglvl > 2 ) {
      fprintf(msgFile, 
              "\n\n bridge->coordFlag = %d", bridge->coordFlag) ;
      fflush(msgFile) ;
   }
   if ( bridge->coordFlag == GLOBAL ) {
      if ( bridge->prbtype == 1 ) {
         if ( msglvl > 2 ) {
            fprintf(msgFile, "\n\n ready to permute B") ;
            fflush(msgFile) ;
         }
         MatMul_setLocalIndices(bridge->info, bridge->B) ;
         if ( msglvl > 2 ) {
            fprintf(msgFile, "\n\n matrix B in local coordinates") ;
            InpMtx_writeForHumanEye(bridge->B, msgFile) ;
            fflush(msgFile) ;
         }
      } else if ( bridge->prbtype == 2 ) {
         if ( msglvl > 2 ) {
            fprintf(msgFile, "\n\n ready to permute A") ;
            fflush(msgFile) ;
         }
         MatMul_setLocalIndices(bridge->info, bridge->A) ;
         if ( msglvl > 2 ) {
            fprintf(msgFile, "\n\n matrix A in local coordinates") ;
            InpMtx_writeForHumanEye(bridge->A, msgFile) ;
            fflush(msgFile) ;
         }
      }
      bridge->coordFlag = LOCAL ;
   }
/*
   --------------------------------------------------
   check to see that Xloc and Yloc are the right size
   --------------------------------------------------
*/
   if ( Xloc->nrow != nrows ) {
      fprintf(stderr, 
              "\n\n fatal error in MatMulMPI, nrows %d, Xloc->nrow %d",
              nrows, Xloc->nrow) ;
      exit(-1) ;
   }
   if ( Xloc->ncol != ncols ) {
      IV_sizeAndEntries(bridge->myownedIV, &nmyowned, &owned) ;
      DenseMtx_clearData(Xloc) ;
      DenseMtx_init(Xloc, SPOOLES_REAL, 0, 0, 
                    nmyowned, ncols, 1, nmyowned) ;
      DenseMtx_rowIndices(Xloc, &n, &list) ;
      IVcopy(n, list, owned) ;
      DenseMtx_clearData(Yloc) ;
      DenseMtx_init(Yloc, SPOOLES_REAL, 0, 0, 
                    nmyowned, ncols, 1, nmyowned) ;
      DenseMtx_rowIndices(Yloc, &n, &list) ;
      IVcopy(n, list, owned) ;
   }
/*
   ------------------
   copy x[] into Xloc
   ------------------
*/
   DVcopy(nent, DenseMtx_entries(Xloc), x) ;
/*
   ---------
   zero Yloc
   ---------
*/
   DenseMtx_zero(Yloc) ;
/*
   ----------------------------------------
   compute the local matrix-vector multiply
   ----------------------------------------
*/
   if ( *pprbtype == 1 ) {
      IVzero(4, stats) ;
      MatMul_MPI_mmm(bridge->info, Yloc, alpha, bridge->B,
                     Xloc, stats, msglvl, msgFile, tag, comm) ;
   } else if ( *pprbtype == 2 ) {
      IVzero(4, stats) ;
      MatMul_MPI_mmm(bridge->info, Yloc, alpha, bridge->A,
                     Xloc, stats, msglvl, msgFile, tag, comm) ;
   }
   if ( msglvl > 2 ) {
      fprintf(msgFile, "\n\n after mvm, Yloc") ;
      DenseMtx_writeForHumanEye(Yloc, msgFile) ;
      fflush(msgFile) ;
   }
/*
   -----------------------------
   copy entries of Yloc into y[]
   -----------------------------
*/
   if ( DenseMtx_entries(Yloc) == NULL ) {
      fprintf(stderr, 
              "\n\n fatal error in MatMulMPI, y <-- Yloc, Yloc is NULL") ;
      exit(-1) ;
   }
   if ( y == NULL ) {
      fprintf(stderr, "\n\n fatal error in MatMulMPI, y <-- Yloc, y is NULL") ;
      exit(-1) ;
   }
   DVcopy(nent, y, DenseMtx_entries(Yloc)) ;
}
#if MYDEBUG > 0
MARKTIME(t2) ;
time_MatMul += t2 - t1 ;
if ( bridge->myid == 0 ) {
   fprintf(stdout, ", %8.3f seconds, %8.3f total time",
           t2 - t1, time_MatMul) ;
   fflush(stdout) ;
}
#endif
#if MYDEBUG > 1
fprintf(bridge->msgFile, ", %8.3f seconds, %8.3f total time",
        t2 - t1, time_MatMul) ;
fflush(bridge->msgFile) ;
#endif

return ; }

/*--------------------------------------------------------------------*/