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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
|
/* SetupMT.c */
#include "../BridgeMT.h"
#define MYDEBUG 1
#if MYDEBUG > 0
static int count_Setup = 0 ;
static double time_Setup = 0.0 ;
#endif
/*--------------------------------------------------------------------*/
/*
------------------------------------------------------------------
purpose --
given InpMtx objects that contain A and B, initialize the bridge
data structure for the multithreaded factor's, solve's and mvm's.
data -- pointer to a Bridge object
pprbtype -- pointer to value containing problem type
*prbtype = 1 --> A X = B X Lambda, vibration problem
*prbtype = 2 --> A X = B X Lambda, buckling problem
*prbtype = 3 --> A X = X Lambda, simple eigenvalue problem
pneqns -- pointer to value containing number of equations
pmxbsz -- pointer to value containing blocksize
A -- pointer to InpMtx object containing A
B -- pointer to InpMtx object containing B
pseed -- pointer to value containing a random number seed
pmsglvl -- pointer to value containing a message level
msgFile -- message file pointer
pnthread -- pointer to value containing # of threads
return value --
1 -- normal return
-1 -- data is NULL
-2 -- pprbtype is NULL
-3 -- *pprbtype is invalid
-4 -- pneqns is NULL
-5 -- *pneqns is invalid
-6 -- pmxbsz is NULL
-7 -- *pmxbsz is invalid
-8 -- A and B are NULL
-9 -- pseed is NULL
-10 -- pmsglvl is NULL
-11 -- *pmsglvl > 0 and msgFile is NULL
-12 -- pnthreads is NULL
-13 -- *pnthreads is invalid
created -- 98aug10, cca
------------------------------------------------------------------
*/
int
SetupMT (
void *data,
int *pprbtype,
int *pneqns,
int *pmxbsz,
InpMtx *A,
InpMtx *B,
int *pseed,
int *pnthread,
int *pmsglvl,
FILE *msgFile
) {
BridgeMT *bridge = (BridgeMT *) data ;
double sigma[2] ;
DV *cumopsDV ;
Graph *graph ;
int maxdomainsize, maxsize, maxzeros, msglvl, mxbsz,
nedges, neqns, nthread, prbtype, seed ;
IVL *adjIVL ;
#if MYDEBUG > 0
double t1, t2 ;
MARKTIME(t1) ;
count_Setup++ ;
fprintf(stdout, "\n (%d) SetupMT()", count_Setup) ;
fflush(stdout) ;
#endif
/*
--------------------
check the input data
--------------------
*/
if ( data == NULL ) {
fprintf(stderr, "\n fatal error in SetupMT()"
"\n data is NULL\n") ;
return(-1) ;
}
if ( pprbtype == NULL ) {
fprintf(stderr, "\n fatal error in SetupMT()"
"\n pprbtype is NULL\n") ;
return(-2) ;
}
prbtype = *pprbtype ;
if ( prbtype < 1 || prbtype > 3 ) {
fprintf(stderr, "\n fatal error in SetupMT()"
"\n prbtype = %d, is invalid\n", prbtype) ;
return(-3) ;
}
if ( pneqns == NULL ) {
fprintf(stderr, "\n fatal error in SetupMT()"
"\n pneqns is NULL\n") ;
return(-4) ;
}
neqns = *pneqns ;
if ( neqns <= 0 ) {
fprintf(stderr, "\n fatal error in SetupMT()"
"\n neqns = %d, is invalid\n", neqns) ;
return(-5) ;
}
if ( pmxbsz == NULL ) {
fprintf(stderr, "\n fatal error in SetupMT()"
"\n pmxbsz is NULL\n") ;
return(-6) ;
}
mxbsz = *pmxbsz ;
if ( mxbsz <= 0 ) {
fprintf(stderr, "\n fatal error in SetupMT()"
"\n *pmxbsz = %d, is invalid\n", mxbsz) ;
return(-7) ;
}
if ( A == NULL && B == NULL ) {
fprintf(stderr, "\n fatal error in SetupMT()"
"\n A and B are NULL\n") ;
return(-8) ;
}
if ( pseed == NULL ) {
fprintf(stderr, "\n fatal error in SetupMT()"
"\n pseed is NULL\n") ;
return(-9) ;
}
seed = *pseed ;
if ( pmsglvl == NULL ) {
fprintf(stderr, "\n fatal error in SetupMT()"
"\n pmsglvl is NULL\n") ;
return(-10) ;
}
msglvl = *pmsglvl ;
if ( msglvl > 0 && msgFile == NULL ) {
fprintf(stderr, "\n fatal error in SetupMT()"
"\n msglvl = %d, msgFile = NULL\n", msglvl) ;
return(-11) ;
}
if ( pnthread == NULL ) {
fprintf(stderr, "\n fatal error in SetupMT()"
"\n pnthread is NULL\n") ;
return(-12) ;
}
nthread = *pnthread ;
if ( nthread <= 0 ) {
fprintf(stderr, "\n fatal error in SetupMT()"
"\n nthread = %d, is invalid\n", nthread) ;
return(-13) ;
}
bridge->msglvl = *pmsglvl ;
/*
bridge->msglvl = 2 ;
*/
bridge->msgFile = msgFile ;
if ( msglvl > 2 ) {
fprintf(msgFile, "\n\n inside SetupMT()"
"\n neqns = %d, prbtype = %d, mxbsz = %d, seed = %d, nthread = %d",
neqns, prbtype, mxbsz, seed, nthread) ;
if ( A != NULL ) {
fprintf(msgFile, "\n\n matrix A") ;
InpMtx_writeForHumanEye(A, msgFile) ;
}
if ( B != NULL ) {
fprintf(msgFile, "\n\n matrix B") ;
InpMtx_writeForHumanEye(B, msgFile) ;
}
fflush(msgFile) ;
}
bridge->prbtype = prbtype ;
bridge->neqns = neqns ;
bridge->mxbsz = mxbsz ;
bridge->A = A ;
bridge->B = B ;
bridge->seed = seed ;
bridge->nthread = nthread ;
/*
----------------------------
create and initialize pencil
----------------------------
*/
sigma[0] = 1.0; sigma[1] = 0.0;
bridge->pencil = Pencil_new() ;
Pencil_setDefaultFields(bridge->pencil) ;
Pencil_init(bridge->pencil, SPOOLES_REAL, SPOOLES_SYMMETRIC,
A, sigma, B) ;
/*
--------------------------------
convert to row or column vectors
--------------------------------
*/
if ( A != NULL ) {
if ( ! INPMTX_IS_BY_ROWS(A) && ! INPMTX_IS_BY_COLUMNS(A) ) {
InpMtx_changeCoordType(A, INPMTX_BY_ROWS) ;
}
if ( ! INPMTX_IS_BY_VECTORS(A) ) {
InpMtx_changeStorageMode(A, INPMTX_BY_VECTORS) ;
}
}
if ( B != NULL ) {
if ( ! INPMTX_IS_BY_ROWS(B) && ! INPMTX_IS_BY_COLUMNS(B) ) {
InpMtx_changeCoordType(B, INPMTX_BY_ROWS) ;
}
if ( ! INPMTX_IS_BY_VECTORS(B) ) {
InpMtx_changeStorageMode(B, INPMTX_BY_VECTORS) ;
}
}
/*
-------------------------------
create a Graph object for A + B
-------------------------------
*/
graph = Graph_new() ;
adjIVL = Pencil_fullAdjacency(bridge->pencil);
nedges = IVL_tsize(adjIVL),
Graph_init2(graph, 0, bridge->neqns, 0, nedges,
bridge->neqns, nedges, adjIVL, NULL, NULL) ;
if ( msglvl > 2 ) {
fprintf(msgFile, "\n\n graph of the input matrix") ;
Graph_writeForHumanEye(graph, msgFile) ;
fflush(msgFile) ;
}
/*
---------------
order the graph
---------------
*/
maxdomainsize = neqns / 64 ;
if ( maxdomainsize == 0 ) {
maxdomainsize = 1 ;
}
maxzeros = (int) (0.01*neqns) ;
maxsize = 64 ;
bridge->frontETree = orderViaBestOfNDandMS(graph, maxdomainsize,
maxzeros, maxsize, bridge->seed, msglvl, msgFile) ;
if ( msglvl > 2 ) {
fprintf(msgFile, "\n\n front tree from ordering") ;
ETree_writeForHumanEye(bridge->frontETree, msgFile) ;
fflush(msgFile) ;
}
/*
----------------------------------------------
get the old-to-new and new-to-old permutations
----------------------------------------------
*/
bridge->oldToNewIV = ETree_oldToNewVtxPerm(bridge->frontETree) ;
bridge->newToOldIV = ETree_newToOldVtxPerm(bridge->frontETree) ;
if ( msglvl > 2 ) {
fprintf(msgFile, "\n\n old-to-new permutation") ;
IV_writeForHumanEye(bridge->oldToNewIV, msgFile) ;
fprintf(msgFile, "\n\n new-to-old permutation") ;
IV_writeForHumanEye(bridge->newToOldIV, msgFile) ;
fflush(msgFile) ;
}
/*
--------------------------------------
permute the vertices in the front tree
--------------------------------------
*/
ETree_permuteVertices(bridge->frontETree, bridge->oldToNewIV) ;
if ( msglvl > 2 ) {
fprintf(msgFile, "\n\n permuted front etree") ;
ETree_writeForHumanEye(bridge->frontETree, msgFile) ;
fflush(msgFile) ;
}
/*
-------------------------------------------
permute the entries in the pencil.
note, after the permutation the
entries are mapped into the upper triangle.
-------------------------------------------
*/
Pencil_permute(bridge->pencil, bridge->oldToNewIV, bridge->oldToNewIV) ;
Pencil_mapToUpperTriangle(bridge->pencil) ;
Pencil_changeCoordType(bridge->pencil, INPMTX_BY_CHEVRONS) ;
Pencil_changeStorageMode(bridge->pencil, INPMTX_BY_VECTORS) ;
if ( msglvl > 2 ) {
fprintf(msgFile, "\n\n permuted pencil") ;
Pencil_writeForHumanEye(bridge->pencil, msgFile) ;
fflush(msgFile) ;
}
/*
----------------------------------
compute the symbolic factorization
----------------------------------
*/
bridge->symbfacIVL = SymbFac_initFromPencil(bridge->frontETree,
bridge->pencil) ;
if ( msglvl > 2 ) {
fprintf(msgFile, "\n\n symbolic factorization") ;
IVL_writeForHumanEye(bridge->symbfacIVL, msgFile) ;
fflush(msgFile) ;
}
/*
--------------------------------------------------
create a FrontMtx object to hold the factorization
--------------------------------------------------
*/
bridge->frontmtx = FrontMtx_new() ;
/*
------------------------------------------------------------
create a SubMtxManager object to hold the factor submatrices
------------------------------------------------------------
*/
bridge->mtxmanager = SubMtxManager_new() ;
SubMtxManager_init(bridge->mtxmanager, LOCK_IN_PROCESS, 0) ;
/*
------------------------------------------------------------
allocate the working objects X and Y for the matrix multiply
------------------------------------------------------------
*/
bridge->X = DenseMtx_new() ;
DenseMtx_init(bridge->X, SPOOLES_REAL, 0, 0, neqns, mxbsz, 1, neqns) ;
bridge->Y = DenseMtx_new() ;
DenseMtx_init(bridge->Y, SPOOLES_REAL, 0, 0, neqns, mxbsz, 1, neqns) ;
/*
--------------------------------------------------------
setup up ownersIV, the map from fronts to owning threads
--------------------------------------------------------
*/
cumopsDV = DV_new() ;
DV_init(cumopsDV, bridge->nthread, NULL );
bridge->ownersIV = ETree_ddMap(bridge->frontETree, SPOOLES_REAL,
SPOOLES_SYMMETRIC, cumopsDV,
1./(2.*bridge->nthread) );
if ( msglvl >= 0 ) {
fprintf(msgFile, "\n\n load balance for the processors") ;
DV_writeForHumanEye(cumopsDV, msgFile) ;
fprintf(msgFile, "\n\n map from fronts to threads") ;
IV_writeForHumanEye(bridge->ownersIV, msgFile) ;
fflush(msgFile) ;
}
/*
-------------------------------------------------------------------
create a SolveMap object, the map from submatries to owning threads
-------------------------------------------------------------------
*/
bridge->solvemap = SolveMap_new() ;
/*
------------------------
free the working storage
------------------------
*/
Graph_free(graph) ;
DV_free(cumopsDV);
#if MYDEBUG > 0
MARKTIME(t2) ;
time_Setup += t2 - t1 ;
fprintf(stdout, ", %8.3f seconds, %8.3f total time",
t2 - t1, time_Setup) ;
fflush(stdout) ;
#endif
return(1) ; }
/*--------------------------------------------------------------------*/
|