| [2aa6644] | 1 | /*BHEADER**********************************************************************
|
|---|
| 2 | * Copyright (c) 2008, Lawrence Livermore National Security, LLC.
|
|---|
| 3 | * Produced at the Lawrence Livermore National Laboratory.
|
|---|
| 4 | * This file is part of HYPRE. See file COPYRIGHT for details.
|
|---|
| 5 | *
|
|---|
| 6 | * HYPRE is free software; you can redistribute it and/or modify it under the
|
|---|
| 7 | * terms of the GNU Lesser General Public License (as published by the Free
|
|---|
| 8 | * Software Foundation) version 2.1 dated February 1999.
|
|---|
| 9 | *
|
|---|
| 10 | * $Revision: 2.4 $
|
|---|
| 11 | ***********************************************************************EHEADER*/
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 | /******************************************************************************
|
|---|
| 16 | *
|
|---|
| 17 | * HYPRE_IJMatrix interface
|
|---|
| 18 | *
|
|---|
| 19 | *****************************************************************************/
|
|---|
| 20 |
|
|---|
| 21 | #include "./IJ_mv.h"
|
|---|
| 22 |
|
|---|
| 23 | #include "../HYPRE.h"
|
|---|
| 24 |
|
|---|
| 25 | /*--------------------------------------------------------------------------
|
|---|
| 26 | * HYPRE_IJMatrixCreate
|
|---|
| 27 | *--------------------------------------------------------------------------*/
|
|---|
| 28 |
|
|---|
| 29 | int HYPRE_IJMatrixCreate( MPI_Comm comm, HYPRE_BigInt ilower, HYPRE_BigInt iupper,
|
|---|
| 30 | HYPRE_BigInt jlower, HYPRE_BigInt jupper, HYPRE_IJMatrix *matrix)
|
|---|
| 31 |
|
|---|
| 32 | {
|
|---|
| 33 |
|
|---|
| 34 | HYPRE_BigInt *row_partitioning;
|
|---|
| 35 | HYPRE_BigInt *col_partitioning;
|
|---|
| 36 | HYPRE_BigInt *info;
|
|---|
| 37 | int num_procs;
|
|---|
| 38 | int myid;
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | hypre_IJMatrix *ijmatrix;
|
|---|
| 42 |
|
|---|
| 43 | #ifdef HYPRE_NO_GLOBAL_PARTITION
|
|---|
| 44 | HYPRE_BigInt row0, col0, rowN, colN;
|
|---|
| 45 | #else
|
|---|
| 46 | HYPRE_BigInt *recv_buf;
|
|---|
| 47 | int i, i4;
|
|---|
| 48 | int square;
|
|---|
| 49 | #endif
|
|---|
| 50 |
|
|---|
| 51 | ijmatrix = hypre_CTAlloc(hypre_IJMatrix, 1);
|
|---|
| 52 |
|
|---|
| 53 | hypre_IJMatrixComm(ijmatrix) = comm;
|
|---|
| 54 | hypre_IJMatrixObject(ijmatrix) = NULL;
|
|---|
| 55 | hypre_IJMatrixTranslator(ijmatrix) = NULL;
|
|---|
| 56 | hypre_IJMatrixObjectType(ijmatrix) = HYPRE_UNITIALIZED;
|
|---|
| 57 | hypre_IJMatrixAssembleFlag(ijmatrix) = 0;
|
|---|
| 58 |
|
|---|
| 59 | MPI_Comm_size(comm,&num_procs);
|
|---|
| 60 | MPI_Comm_rank(comm, &myid);
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | if (ilower > iupper+1 || ilower < 0)
|
|---|
| 64 | {
|
|---|
| 65 | hypre_error_in_arg(2);
|
|---|
| 66 | return hypre_error_flag;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | if (iupper < -1)
|
|---|
| 70 | {
|
|---|
| 71 | hypre_error_in_arg(3);
|
|---|
| 72 | return hypre_error_flag;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | if (jlower > jupper+1 || jlower < 0)
|
|---|
| 76 | {
|
|---|
| 77 | hypre_error_in_arg(4);
|
|---|
| 78 | return hypre_error_flag;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | if (jupper < -1)
|
|---|
| 82 | {
|
|---|
| 83 | hypre_error_in_arg(5);
|
|---|
| 84 | return hypre_error_flag;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | #ifdef HYPRE_NO_GLOBAL_PARTITION
|
|---|
| 89 |
|
|---|
| 90 | info = hypre_CTAlloc(HYPRE_BigInt,2);
|
|---|
| 91 |
|
|---|
| 92 | row_partitioning = hypre_CTAlloc(HYPRE_BigInt, 2);
|
|---|
| 93 | col_partitioning = hypre_CTAlloc(HYPRE_BigInt, 2);
|
|---|
| 94 |
|
|---|
| 95 | row_partitioning[0] = ilower;
|
|---|
| 96 | row_partitioning[1] = iupper+1;
|
|---|
| 97 | col_partitioning[0] = jlower;
|
|---|
| 98 | col_partitioning[1] = jupper+1;
|
|---|
| 99 |
|
|---|
| 100 | /* now we need the global number of rows and columns as well
|
|---|
| 101 | as the global first row and column index */
|
|---|
| 102 |
|
|---|
| 103 | /* proc 0 has the first row and col */
|
|---|
| 104 | if (myid==0)
|
|---|
| 105 | {
|
|---|
| 106 | info[0] = ilower;
|
|---|
| 107 | info[1] = jlower;
|
|---|
| 108 | }
|
|---|
| 109 | MPI_Bcast(info, 2, MPI_HYPRE_BIG_INT, 0, comm);
|
|---|
| 110 | row0 = info[0];
|
|---|
| 111 | col0 = info[1];
|
|---|
| 112 |
|
|---|
| 113 | /* proc (num_procs-1) has the last row and col */
|
|---|
| 114 | if (myid == (num_procs-1))
|
|---|
| 115 | {
|
|---|
| 116 | info[0] = iupper;
|
|---|
| 117 | info[1] = jupper;
|
|---|
| 118 | }
|
|---|
| 119 | MPI_Bcast(info, 2, MPI_HYPRE_BIG_INT, num_procs-1, comm);
|
|---|
| 120 |
|
|---|
| 121 | rowN = info[0];
|
|---|
| 122 | colN = info[1];
|
|---|
| 123 |
|
|---|
| 124 | hypre_IJMatrixGlobalFirstRow(ijmatrix) = row0;
|
|---|
| 125 | hypre_IJMatrixGlobalFirstCol(ijmatrix) = col0;
|
|---|
| 126 | hypre_IJMatrixGlobalNumRows(ijmatrix) = rowN - row0 + 1;
|
|---|
| 127 | hypre_IJMatrixGlobalNumCols(ijmatrix) = colN - col0 + 1;
|
|---|
| 128 |
|
|---|
| 129 | hypre_TFree(info);
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 | #else
|
|---|
| 133 |
|
|---|
| 134 | info = hypre_CTAlloc(HYPRE_BigInt,4);
|
|---|
| 135 | recv_buf = hypre_CTAlloc(HYPRE_BigInt,4*num_procs);
|
|---|
| 136 | row_partitioning = hypre_CTAlloc(HYPRE_BigInt, num_procs+1);
|
|---|
| 137 |
|
|---|
| 138 | info[0] = ilower;
|
|---|
| 139 | info[1] = iupper;
|
|---|
| 140 | info[2] = jlower;
|
|---|
| 141 | info[3] = jupper;
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 | /* Generate row- and column-partitioning through information exchange
|
|---|
| 145 | across all processors, check whether the matrix is square, and
|
|---|
| 146 | if the partitionings match. i.e. no overlaps or gaps,
|
|---|
| 147 | if there are overlaps or gaps in the row partitioning or column
|
|---|
| 148 | partitioning , ierr will be set to -9 or -10, respectively */
|
|---|
| 149 |
|
|---|
| 150 | MPI_Allgather(info,4,MPI_HYPRE_BIG_INT,recv_buf,4,MPI_HYPRE_BIG_INT,comm);
|
|---|
| 151 |
|
|---|
| 152 | row_partitioning[0] = recv_buf[0];
|
|---|
| 153 | square = 1;
|
|---|
| 154 | for (i=0; i < num_procs-1; i++)
|
|---|
| 155 | {
|
|---|
| 156 | i4 = 4*i;
|
|---|
| 157 | if ( recv_buf[i4+1] != (recv_buf[i4+4]-1) )
|
|---|
| 158 | {
|
|---|
| 159 | printf("Warning -- row partitioning does not line up! Partitioning incomplete!\n");
|
|---|
| 160 | hypre_error(HYPRE_ERROR_GENERIC);
|
|---|
| 161 | return hypre_error_flag;
|
|---|
| 162 | }
|
|---|
| 163 | else
|
|---|
| 164 | row_partitioning[i+1] = recv_buf[i4+4];
|
|---|
| 165 |
|
|---|
| 166 | if ((square && (recv_buf[i4] != recv_buf[i4+2])) ||
|
|---|
| 167 | (recv_buf[i4+1] != recv_buf[i4+3]) )
|
|---|
| 168 | {
|
|---|
| 169 | square = 0;
|
|---|
| 170 | }
|
|---|
| 171 | }
|
|---|
| 172 | i4 = (num_procs-1)*4;
|
|---|
| 173 | row_partitioning[num_procs] = recv_buf[i4+1]+1;
|
|---|
| 174 |
|
|---|
| 175 | if ((recv_buf[i4] != recv_buf[i4+2]) || (recv_buf[i4+1] != recv_buf[i4+3]))
|
|---|
| 176 | square = 0;
|
|---|
| 177 |
|
|---|
| 178 | if (square)
|
|---|
| 179 | col_partitioning = row_partitioning;
|
|---|
| 180 | else
|
|---|
| 181 | {
|
|---|
| 182 | col_partitioning = hypre_CTAlloc(HYPRE_BigInt,num_procs+1);
|
|---|
| 183 | col_partitioning[0] = recv_buf[2];
|
|---|
| 184 | for (i=0; i < num_procs-1; i++)
|
|---|
| 185 | {
|
|---|
| 186 | i4 = 4*i;
|
|---|
| 187 | if (recv_buf[i4+3] != recv_buf[i4+6]-1)
|
|---|
| 188 | {
|
|---|
| 189 | printf("Warning -- col partitioning does not line up! Partitioning incomplete!\n");
|
|---|
| 190 | hypre_error(HYPRE_ERROR_GENERIC);
|
|---|
| 191 | return hypre_error_flag;
|
|---|
| 192 | }
|
|---|
| 193 | else
|
|---|
| 194 | col_partitioning[i+1] = recv_buf[i4+6];
|
|---|
| 195 | }
|
|---|
| 196 | col_partitioning[num_procs] = recv_buf[num_procs*4-1]+1;
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 | hypre_IJMatrixGlobalFirstRow(ijmatrix) = row_partitioning[0];
|
|---|
| 202 | hypre_IJMatrixGlobalFirstCol(ijmatrix) = col_partitioning[0];
|
|---|
| 203 | hypre_IJMatrixGlobalNumRows(ijmatrix) = row_partitioning[num_procs] -
|
|---|
| 204 | row_partitioning[0];
|
|---|
| 205 | hypre_IJMatrixGlobalNumCols(ijmatrix) = col_partitioning[num_procs] -
|
|---|
| 206 | col_partitioning[0];
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 | hypre_TFree(info);
|
|---|
| 211 | hypre_TFree(recv_buf);
|
|---|
| 212 |
|
|---|
| 213 | #endif
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 | hypre_IJMatrixRowPartitioning(ijmatrix) = row_partitioning;
|
|---|
| 217 | hypre_IJMatrixColPartitioning(ijmatrix) = col_partitioning;
|
|---|
| 218 |
|
|---|
| 219 | *matrix = (HYPRE_IJMatrix) ijmatrix;
|
|---|
| 220 |
|
|---|
| 221 | return hypre_error_flag;
|
|---|
| 222 | /* return ierr; */
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | /*--------------------------------------------------------------------------
|
|---|
| 226 | * HYPRE_IJMatrixDestroy
|
|---|
| 227 | *--------------------------------------------------------------------------*/
|
|---|
| 228 |
|
|---|
| 229 | int
|
|---|
| 230 | HYPRE_IJMatrixDestroy( HYPRE_IJMatrix matrix )
|
|---|
| 231 | {
|
|---|
| 232 | int ierr = 0;
|
|---|
| 233 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 234 |
|
|---|
| 235 | if (!ijmatrix)
|
|---|
| 236 | {
|
|---|
| 237 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixDestroy\n");
|
|---|
| 238 | hypre_error_in_arg(1);
|
|---|
| 239 | return hypre_error_flag;
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | if (ijmatrix)
|
|---|
| 243 | {
|
|---|
| 244 | if (hypre_IJMatrixRowPartitioning(ijmatrix) ==
|
|---|
| 245 | hypre_IJMatrixColPartitioning(ijmatrix))
|
|---|
| 246 | hypre_TFree(hypre_IJMatrixRowPartitioning(ijmatrix));
|
|---|
| 247 | else
|
|---|
| 248 | {
|
|---|
| 249 | hypre_TFree(hypre_IJMatrixRowPartitioning(ijmatrix));
|
|---|
| 250 | hypre_TFree(hypre_IJMatrixColPartitioning(ijmatrix));
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | /*
|
|---|
| 254 | if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PETSC )
|
|---|
| 255 | ierr = hypre_IJMatrixDestroyPETSc( ijmatrix );
|
|---|
| 256 | else if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_ISIS )
|
|---|
| 257 | ierr = hypre_IJMatrixDestroyISIS( ijmatrix );
|
|---|
| 258 | else */
|
|---|
| 259 |
|
|---|
| 260 | if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
|
|---|
| 261 | ierr = hypre_IJMatrixDestroyParCSR( ijmatrix );
|
|---|
| 262 | else if ( hypre_IJMatrixObjectType(ijmatrix) != -1 )
|
|---|
| 263 | {
|
|---|
| 264 | printf("Unrecognized object type -- HYPRE_IJMatrixDestroy\n");
|
|---|
| 265 | hypre_error_in_arg(1);
|
|---|
| 266 | return hypre_error_flag;
|
|---|
| 267 | }
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | hypre_TFree(ijmatrix);
|
|---|
| 271 |
|
|---|
| 272 | return hypre_error_flag;
|
|---|
| 273 |
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | /*--------------------------------------------------------------------------
|
|---|
| 277 | * HYPRE_IJMatrixInitialize
|
|---|
| 278 | *--------------------------------------------------------------------------*/
|
|---|
| 279 |
|
|---|
| 280 | int
|
|---|
| 281 | HYPRE_IJMatrixInitialize( HYPRE_IJMatrix matrix )
|
|---|
| 282 | {
|
|---|
| 283 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 284 | int ierr = 0;
|
|---|
| 285 |
|
|---|
| 286 | if (!ijmatrix)
|
|---|
| 287 | {
|
|---|
| 288 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixInitialize\n");
|
|---|
| 289 |
|
|---|
| 290 | hypre_error_in_arg(1);
|
|---|
| 291 | return hypre_error_flag;
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | /* if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PETSC )
|
|---|
| 295 | ierr = hypre_IJMatrixInitializePETSc( ijmatrix ) ;
|
|---|
| 296 | else if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_ISIS )
|
|---|
| 297 | ierr = hypre_IJMatrixInitializeISIS( ijmatrix ) ;
|
|---|
| 298 | else */
|
|---|
| 299 |
|
|---|
| 300 | if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
|
|---|
| 301 | ierr = hypre_IJMatrixInitializeParCSR( ijmatrix ) ;
|
|---|
| 302 | else
|
|---|
| 303 | {
|
|---|
| 304 | printf("Unrecognized object type -- HYPRE_IJMatrixInitialize\n");
|
|---|
| 305 | hypre_error_in_arg(1);
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | return hypre_error_flag;
|
|---|
| 309 |
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 | /*--------------------------------------------------------------------------
|
|---|
| 315 | * HYPRE_IJMatrixSetValues
|
|---|
| 316 | *--------------------------------------------------------------------------*/
|
|---|
| 317 |
|
|---|
| 318 | int
|
|---|
| 319 | HYPRE_IJMatrixSetValues( HYPRE_IJMatrix matrix, int nrows,
|
|---|
| 320 | int *ncols, const HYPRE_BigInt *rows,
|
|---|
| 321 | const HYPRE_BigInt *cols, const double *values)
|
|---|
| 322 | {
|
|---|
| 323 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 324 |
|
|---|
| 325 | if (nrows == 0)
|
|---|
| 326 | return hypre_error_flag;
|
|---|
| 327 |
|
|---|
| 328 | if (!ijmatrix)
|
|---|
| 329 | {
|
|---|
| 330 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixSetValues\n");
|
|---|
| 331 | hypre_error_in_arg(1);
|
|---|
| 332 | return hypre_error_flag;
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 | if (nrows < 0)
|
|---|
| 336 | {
|
|---|
| 337 | hypre_error_in_arg(2);
|
|---|
| 338 | return hypre_error_flag;
|
|---|
| 339 | }
|
|---|
| 340 |
|
|---|
| 341 | if (!ncols)
|
|---|
| 342 | {
|
|---|
| 343 | hypre_error_in_arg(3);
|
|---|
| 344 | return hypre_error_flag;
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| 347 | if (!rows)
|
|---|
| 348 | {
|
|---|
| 349 | hypre_error_in_arg(4);
|
|---|
| 350 | return hypre_error_flag;
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | if (!cols)
|
|---|
| 354 | {
|
|---|
| 355 | hypre_error_in_arg(5);
|
|---|
| 356 | return hypre_error_flag;
|
|---|
| 357 | }
|
|---|
| 358 |
|
|---|
| 359 | if (!values)
|
|---|
| 360 | {
|
|---|
| 361 | hypre_error_in_arg(6);
|
|---|
| 362 | return hypre_error_flag;
|
|---|
| 363 | }
|
|---|
| 364 |
|
|---|
| 365 | /* if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PETSC )
|
|---|
| 366 | return( hypre_IJMatrixSetValuesPETSc( ijmatrix, nrows, ncols,
|
|---|
| 367 | rows, cols, values ) );
|
|---|
| 368 | else if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_ISIS )
|
|---|
| 369 | return( hypre_IJMatrixSetValuesISIS( ijmatrix, nrows, ncols,
|
|---|
| 370 | rows, cols, values ) );
|
|---|
| 371 | else */
|
|---|
| 372 |
|
|---|
| 373 | if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
|
|---|
| 374 | return( hypre_IJMatrixSetValuesParCSR( ijmatrix, nrows, ncols,
|
|---|
| 375 | rows, cols, values ) );
|
|---|
| 376 | else
|
|---|
| 377 | {
|
|---|
| 378 | printf("Unrecognized object type -- HYPRE_IJMatrixSetValues\n");
|
|---|
| 379 | hypre_error_in_arg(1);
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | return hypre_error_flag;
|
|---|
| 383 |
|
|---|
| 384 | }
|
|---|
| 385 |
|
|---|
| 386 | /*--------------------------------------------------------------------------
|
|---|
| 387 | * HYPRE_IJMatrixAddToValues
|
|---|
| 388 | *--------------------------------------------------------------------------*/
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 | int
|
|---|
| 392 | HYPRE_IJMatrixAddToValues( HYPRE_IJMatrix matrix, int nrows,
|
|---|
| 393 | int *ncols, const HYPRE_BigInt *rows,
|
|---|
| 394 | const HYPRE_BigInt *cols, const double *values)
|
|---|
| 395 | {
|
|---|
| 396 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 397 |
|
|---|
| 398 | if (nrows == 0)
|
|---|
| 399 | return hypre_error_flag;
|
|---|
| 400 |
|
|---|
| 401 | if (!ijmatrix)
|
|---|
| 402 | {
|
|---|
| 403 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixAddToValues\n");
|
|---|
| 404 | hypre_error_in_arg(1);
|
|---|
| 405 | return hypre_error_flag;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | if (nrows < 0)
|
|---|
| 409 | {
|
|---|
| 410 | hypre_error_in_arg(2);
|
|---|
| 411 | return hypre_error_flag;
|
|---|
| 412 | }
|
|---|
| 413 |
|
|---|
| 414 | if (!ncols)
|
|---|
| 415 | {
|
|---|
| 416 | hypre_error_in_arg(3);
|
|---|
| 417 | return hypre_error_flag;
|
|---|
| 418 | }
|
|---|
| 419 |
|
|---|
| 420 | if (!rows)
|
|---|
| 421 | {
|
|---|
| 422 | hypre_error_in_arg(4);
|
|---|
| 423 | return hypre_error_flag;
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | if (!cols)
|
|---|
| 427 | {
|
|---|
| 428 | hypre_error_in_arg(5);
|
|---|
| 429 | return hypre_error_flag;
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 | if (!values)
|
|---|
| 433 | {
|
|---|
| 434 | hypre_error_in_arg(6);
|
|---|
| 435 | return hypre_error_flag;
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | /* if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PETSC )
|
|---|
| 439 | return( hypre_IJMatrixAddToValuesPETSc( ijmatrix, nrows, ncols,
|
|---|
| 440 | rows, cols, values ) );
|
|---|
| 441 | else if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_ISIS )
|
|---|
| 442 | return( hypre_IJMatrixAddToValuesISIS( ijmatrix, nrows, ncols,
|
|---|
| 443 | rows, cols, values ) );
|
|---|
| 444 | else */
|
|---|
| 445 |
|
|---|
| 446 | if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
|
|---|
| 447 | return( hypre_IJMatrixAddToValuesParCSR( ijmatrix, nrows, ncols,
|
|---|
| 448 | rows, cols, values ) );
|
|---|
| 449 | else
|
|---|
| 450 | {
|
|---|
| 451 | printf("Unrecognized object type -- HYPRE_IJMatrixAddToValues\n");
|
|---|
| 452 | hypre_error_in_arg(1);
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | return hypre_error_flag;
|
|---|
| 456 |
|
|---|
| 457 | }
|
|---|
| 458 |
|
|---|
| 459 | /*--------------------------------------------------------------------------
|
|---|
| 460 | * HYPRE_IJMatrixAssemble
|
|---|
| 461 | *--------------------------------------------------------------------------*/
|
|---|
| 462 |
|
|---|
| 463 | int
|
|---|
| 464 | HYPRE_IJMatrixAssemble( HYPRE_IJMatrix matrix )
|
|---|
| 465 | {
|
|---|
| 466 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 467 |
|
|---|
| 468 | if (!ijmatrix)
|
|---|
| 469 | {
|
|---|
| 470 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixAssemble\n");
|
|---|
| 471 | hypre_error_in_arg(1);
|
|---|
| 472 | return hypre_error_flag;
|
|---|
| 473 | }
|
|---|
| 474 |
|
|---|
| 475 | /* if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PETSC )
|
|---|
| 476 | return( hypre_IJMatrixAssemblePETSc( ijmatrix ) );
|
|---|
| 477 | else if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_ISIS )
|
|---|
| 478 | return( hypre_IJMatrixAssembleISIS( ijmatrix ) );
|
|---|
| 479 | else */
|
|---|
| 480 |
|
|---|
| 481 | if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
|
|---|
| 482 | return( hypre_IJMatrixAssembleParCSR( ijmatrix ) );
|
|---|
| 483 | else
|
|---|
| 484 | {
|
|---|
| 485 | printf("Unrecognized object type -- HYPRE_IJMatrixAssemble\n");
|
|---|
| 486 | hypre_error_in_arg(1);
|
|---|
| 487 | }
|
|---|
| 488 |
|
|---|
| 489 | return hypre_error_flag;
|
|---|
| 490 | }
|
|---|
| 491 |
|
|---|
| 492 | /*--------------------------------------------------------------------------
|
|---|
| 493 | * HYPRE_IJMatrixGetRowCounts
|
|---|
| 494 | *--------------------------------------------------------------------------*/
|
|---|
| 495 |
|
|---|
| 496 | int
|
|---|
| 497 | HYPRE_IJMatrixGetRowCounts( HYPRE_IJMatrix matrix, int nrows,
|
|---|
| 498 | HYPRE_BigInt *rows, int *ncols )
|
|---|
| 499 | {
|
|---|
| 500 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 501 |
|
|---|
| 502 | if (nrows == 0) return hypre_error_flag;
|
|---|
| 503 |
|
|---|
| 504 | if (!ijmatrix)
|
|---|
| 505 | {
|
|---|
| 506 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixGetRowCounts\n");
|
|---|
| 507 | hypre_error_in_arg(1);
|
|---|
| 508 | return hypre_error_flag;
|
|---|
| 509 | }
|
|---|
| 510 |
|
|---|
| 511 | if (nrows < 0)
|
|---|
| 512 | {
|
|---|
| 513 | hypre_error_in_arg(2);
|
|---|
| 514 | return hypre_error_flag;
|
|---|
| 515 | }
|
|---|
| 516 |
|
|---|
| 517 | if (!rows)
|
|---|
| 518 | {
|
|---|
| 519 | hypre_error_in_arg(3);
|
|---|
| 520 | return hypre_error_flag;
|
|---|
| 521 | }
|
|---|
| 522 |
|
|---|
| 523 | if (!ncols)
|
|---|
| 524 | {
|
|---|
| 525 | hypre_error_in_arg(4);
|
|---|
| 526 | return hypre_error_flag;
|
|---|
| 527 | }
|
|---|
| 528 |
|
|---|
| 529 | /* if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PETSC )
|
|---|
| 530 | ierr = hypre_IJMatrixGetRowCountsPETSc( ijmatrix, nrows, rows, ncols );
|
|---|
| 531 | else if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_ISIS )
|
|---|
| 532 | ierr = hypre_IJMatrixGetRowCountsISIS( ijmatrix, nrows, rows, ncols );
|
|---|
| 533 | else */
|
|---|
| 534 |
|
|---|
| 535 | if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
|
|---|
| 536 | hypre_IJMatrixGetRowCountsParCSR( ijmatrix, nrows, rows, ncols );
|
|---|
| 537 | else
|
|---|
| 538 | {
|
|---|
| 539 | printf("Unrecognized object type -- HYPRE_IJMatrixGetRowCounts\n");
|
|---|
| 540 | hypre_error_in_arg(1);
|
|---|
| 541 | }
|
|---|
| 542 |
|
|---|
| 543 | return hypre_error_flag;
|
|---|
| 544 | }
|
|---|
| 545 |
|
|---|
| 546 | /*--------------------------------------------------------------------------
|
|---|
| 547 | * HYPRE_IJMatrixGetValues
|
|---|
| 548 | *--------------------------------------------------------------------------*/
|
|---|
| 549 |
|
|---|
| 550 | int
|
|---|
| 551 | HYPRE_IJMatrixGetValues( HYPRE_IJMatrix matrix, int nrows, int *ncols,
|
|---|
| 552 | HYPRE_BigInt *rows, HYPRE_BigInt *cols, double *values)
|
|---|
| 553 | {
|
|---|
| 554 | int ierr = 0;
|
|---|
| 555 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 556 |
|
|---|
| 557 | if (nrows == 0) return hypre_error_flag;
|
|---|
| 558 |
|
|---|
| 559 | if (!ijmatrix)
|
|---|
| 560 | {
|
|---|
| 561 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixGetValues\n");
|
|---|
| 562 | hypre_error_in_arg(1);
|
|---|
| 563 | return hypre_error_flag;
|
|---|
| 564 | }
|
|---|
| 565 |
|
|---|
| 566 | if (nrows < 0)
|
|---|
| 567 | {
|
|---|
| 568 | hypre_error_in_arg(2);
|
|---|
| 569 | return hypre_error_flag;
|
|---|
| 570 | }
|
|---|
| 571 |
|
|---|
| 572 | if (!ncols)
|
|---|
| 573 | {
|
|---|
| 574 | hypre_error_in_arg(3);
|
|---|
| 575 | return hypre_error_flag;
|
|---|
| 576 | }
|
|---|
| 577 |
|
|---|
| 578 | if (!rows)
|
|---|
| 579 | {
|
|---|
| 580 | hypre_error_in_arg(4);
|
|---|
| 581 | return hypre_error_flag;
|
|---|
| 582 | }
|
|---|
| 583 |
|
|---|
| 584 | if (!cols)
|
|---|
| 585 | {
|
|---|
| 586 | hypre_error_in_arg(5);
|
|---|
| 587 | return hypre_error_flag;
|
|---|
| 588 | }
|
|---|
| 589 |
|
|---|
| 590 | if (!values)
|
|---|
| 591 | {
|
|---|
| 592 | hypre_error_in_arg(6);
|
|---|
| 593 | return hypre_error_flag;
|
|---|
| 594 | }
|
|---|
| 595 |
|
|---|
| 596 | /* if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PETSC )
|
|---|
| 597 | ierr = hypre_IJMatrixGetValuesPETSc( ijmatrix, nrows, ncols,
|
|---|
| 598 | rows, cols, values );
|
|---|
| 599 | else if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_ISIS )
|
|---|
| 600 | ierr = hypre_IJMatrixGetValuesISIS( ijmatrix, nrows, ncols,
|
|---|
| 601 | rows, cols, values );
|
|---|
| 602 | else */
|
|---|
| 603 |
|
|---|
| 604 | if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
|
|---|
| 605 | ierr = hypre_IJMatrixGetValuesParCSR( ijmatrix, nrows, ncols,
|
|---|
| 606 | rows, cols, values );
|
|---|
| 607 | else
|
|---|
| 608 | {
|
|---|
| 609 | printf("Unrecognized object type -- HYPRE_IJMatrixGetValues\n");
|
|---|
| 610 | hypre_error_in_arg(1);
|
|---|
| 611 | }
|
|---|
| 612 |
|
|---|
| 613 | return hypre_error_flag;
|
|---|
| 614 |
|
|---|
| 615 | }
|
|---|
| 616 |
|
|---|
| 617 | /*--------------------------------------------------------------------------
|
|---|
| 618 | * HYPRE_IJMatrixSetObjectType
|
|---|
| 619 | *--------------------------------------------------------------------------*/
|
|---|
| 620 |
|
|---|
| 621 | int
|
|---|
| 622 | HYPRE_IJMatrixSetObjectType( HYPRE_IJMatrix matrix, int type )
|
|---|
| 623 | {
|
|---|
| 624 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 625 |
|
|---|
| 626 | if (!ijmatrix)
|
|---|
| 627 | {
|
|---|
| 628 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixSetObjectType\n");
|
|---|
| 629 | hypre_error_in_arg(1);
|
|---|
| 630 | return hypre_error_flag;
|
|---|
| 631 | }
|
|---|
| 632 |
|
|---|
| 633 | hypre_IJMatrixObjectType(ijmatrix) = type;
|
|---|
| 634 |
|
|---|
| 635 | return hypre_error_flag;
|
|---|
| 636 | }
|
|---|
| 637 |
|
|---|
| 638 | /*--------------------------------------------------------------------------
|
|---|
| 639 | * HYPRE_IJMatrixGetObjectType
|
|---|
| 640 | *--------------------------------------------------------------------------*/
|
|---|
| 641 |
|
|---|
| 642 | int
|
|---|
| 643 | HYPRE_IJMatrixGetObjectType( HYPRE_IJMatrix matrix, int *type )
|
|---|
| 644 | {
|
|---|
| 645 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 646 |
|
|---|
| 647 | if (!ijmatrix)
|
|---|
| 648 | {
|
|---|
| 649 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixGetObjectType\n");
|
|---|
| 650 | hypre_error_in_arg(1);
|
|---|
| 651 | return hypre_error_flag;
|
|---|
| 652 | }
|
|---|
| 653 |
|
|---|
| 654 | *type = hypre_IJMatrixObjectType(ijmatrix);
|
|---|
| 655 | return hypre_error_flag;
|
|---|
| 656 | /* return 0; */
|
|---|
| 657 | }
|
|---|
| 658 |
|
|---|
| 659 | /*--------------------------------------------------------------------------
|
|---|
| 660 | * HYPRE_IJMatrixGetLocalRange
|
|---|
| 661 | *--------------------------------------------------------------------------*/
|
|---|
| 662 |
|
|---|
| 663 | int
|
|---|
| 664 | HYPRE_IJMatrixGetLocalRange( HYPRE_IJMatrix matrix, HYPRE_BigInt *ilower,
|
|---|
| 665 | HYPRE_BigInt *iupper,
|
|---|
| 666 | HYPRE_BigInt *jlower, HYPRE_BigInt *jupper )
|
|---|
| 667 | {
|
|---|
| 668 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 669 | MPI_Comm comm;
|
|---|
| 670 | HYPRE_BigInt *row_partitioning;
|
|---|
| 671 | HYPRE_BigInt *col_partitioning;
|
|---|
| 672 | int my_id;
|
|---|
| 673 |
|
|---|
| 674 | if (!ijmatrix)
|
|---|
| 675 | {
|
|---|
| 676 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixGetObjectType\n");
|
|---|
| 677 | hypre_error_in_arg(1);
|
|---|
| 678 | return hypre_error_flag;
|
|---|
| 679 | }
|
|---|
| 680 |
|
|---|
| 681 | comm = hypre_IJMatrixComm(ijmatrix);
|
|---|
| 682 | row_partitioning = hypre_IJMatrixRowPartitioning(ijmatrix);
|
|---|
| 683 | col_partitioning = hypre_IJMatrixColPartitioning(ijmatrix);
|
|---|
| 684 |
|
|---|
| 685 | MPI_Comm_rank(comm, &my_id);
|
|---|
| 686 |
|
|---|
| 687 | #ifdef HYPRE_NO_GLOBAL_PARTITION
|
|---|
| 688 | *ilower = row_partitioning[0];
|
|---|
| 689 | *iupper = row_partitioning[1]-1;
|
|---|
| 690 | *jlower = col_partitioning[0];
|
|---|
| 691 | *jupper = col_partitioning[1]-1;
|
|---|
| 692 | #else
|
|---|
| 693 | *ilower = row_partitioning[my_id];
|
|---|
| 694 | *iupper = row_partitioning[my_id+1]-1;
|
|---|
| 695 | *jlower = col_partitioning[my_id];
|
|---|
| 696 | *jupper = col_partitioning[my_id+1]-1;
|
|---|
| 697 | #endif
|
|---|
| 698 |
|
|---|
| 699 | return hypre_error_flag;
|
|---|
| 700 | /* return 0; */
|
|---|
| 701 | }
|
|---|
| 702 |
|
|---|
| 703 | /*--------------------------------------------------------------------------
|
|---|
| 704 | * HYPRE_IJMatrixGetObject
|
|---|
| 705 | *--------------------------------------------------------------------------*/
|
|---|
| 706 |
|
|---|
| 707 | /**
|
|---|
| 708 | Returns a pointer to an underlying ijmatrix type used to implement IJMatrix.
|
|---|
| 709 | Assumes that the implementation has an underlying matrix, so it would not
|
|---|
| 710 | work with a direct implementation of IJMatrix.
|
|---|
| 711 |
|
|---|
| 712 | @return integer error code
|
|---|
| 713 | @param IJMatrix [IN]
|
|---|
| 714 | The ijmatrix to be pointed to.
|
|---|
| 715 | */
|
|---|
| 716 |
|
|---|
| 717 | int
|
|---|
| 718 | HYPRE_IJMatrixGetObject( HYPRE_IJMatrix matrix, void **object )
|
|---|
| 719 | {
|
|---|
| 720 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 721 |
|
|---|
| 722 | if (!ijmatrix)
|
|---|
| 723 | {
|
|---|
| 724 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixGetObject\n");
|
|---|
| 725 | hypre_error_in_arg(1);
|
|---|
| 726 | return hypre_error_flag;
|
|---|
| 727 | }
|
|---|
| 728 |
|
|---|
| 729 | *object = hypre_IJMatrixObject( ijmatrix );
|
|---|
| 730 |
|
|---|
| 731 | return hypre_error_flag;
|
|---|
| 732 |
|
|---|
| 733 | /* return 0; */
|
|---|
| 734 | }
|
|---|
| 735 |
|
|---|
| 736 | /*--------------------------------------------------------------------------
|
|---|
| 737 | * HYPRE_IJMatrixSetRowSizes
|
|---|
| 738 | *--------------------------------------------------------------------------*/
|
|---|
| 739 |
|
|---|
| 740 | int
|
|---|
| 741 | HYPRE_IJMatrixSetRowSizes( HYPRE_IJMatrix matrix, const int *sizes )
|
|---|
| 742 | {
|
|---|
| 743 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 744 |
|
|---|
| 745 | if (!ijmatrix)
|
|---|
| 746 | {
|
|---|
| 747 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixSetRowSizes\n");
|
|---|
| 748 | hypre_error_in_arg(1);
|
|---|
| 749 | return hypre_error_flag;
|
|---|
| 750 | }
|
|---|
| 751 |
|
|---|
| 752 | /* if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PETSC )
|
|---|
| 753 | return( hypre_IJMatrixSetRowSizesPETSc( ijmatrix , sizes ) );
|
|---|
| 754 | else if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_ISIS )
|
|---|
| 755 | return( hypre_IJMatrixSetRowSizesISIS( ijmatrix , sizes ) );
|
|---|
| 756 | else */
|
|---|
| 757 |
|
|---|
| 758 | if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
|
|---|
| 759 | return( hypre_IJMatrixSetRowSizesParCSR( ijmatrix , sizes ) );
|
|---|
| 760 | else
|
|---|
| 761 | {
|
|---|
| 762 | printf("Unrecognized object type -- HYPRE_IJMatrixSetRowSizes\n");
|
|---|
| 763 | hypre_error_in_arg(1);
|
|---|
| 764 | }
|
|---|
| 765 |
|
|---|
| 766 | return hypre_error_flag;
|
|---|
| 767 | }
|
|---|
| 768 |
|
|---|
| 769 |
|
|---|
| 770 | /*--------------------------------------------------------------------------
|
|---|
| 771 | * HYPRE_IJMatrixSetDiagOffdSizes
|
|---|
| 772 | *--------------------------------------------------------------------------*/
|
|---|
| 773 |
|
|---|
| 774 | int
|
|---|
| 775 | HYPRE_IJMatrixSetDiagOffdSizes( HYPRE_IJMatrix matrix,
|
|---|
| 776 | const int *diag_sizes,
|
|---|
| 777 | const int *offdiag_sizes )
|
|---|
| 778 | {
|
|---|
| 779 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 780 |
|
|---|
| 781 | if (!ijmatrix)
|
|---|
| 782 | {
|
|---|
| 783 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixSetDiagOffdSizes\n");
|
|---|
| 784 | hypre_error_in_arg(1);
|
|---|
| 785 | return hypre_error_flag;
|
|---|
| 786 | }
|
|---|
| 787 |
|
|---|
| 788 | /* if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PETSC )
|
|---|
| 789 | ierr = hypre_IJMatrixSetDiagOffdSizesPETSc( ijmatrix , diag_sizes ,
|
|---|
| 790 | offdiag_sizes );
|
|---|
| 791 | else if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_ISIS )
|
|---|
| 792 | ierr = hypre_IJMatrixSetDiagOffdSizesISIS( ijmatrix , diag_sizes ,
|
|---|
| 793 | offdiag_sizes );
|
|---|
| 794 | else */
|
|---|
| 795 |
|
|---|
| 796 | if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
|
|---|
| 797 | hypre_IJMatrixSetDiagOffdSizesParCSR( ijmatrix , diag_sizes ,
|
|---|
| 798 | offdiag_sizes );
|
|---|
| 799 | else
|
|---|
| 800 | {
|
|---|
| 801 | printf("Unrecognized object type -- HYPRE_IJMatrixSetDiagOffdSizes\n");
|
|---|
| 802 | hypre_error_in_arg(1);
|
|---|
| 803 | }
|
|---|
| 804 | return hypre_error_flag;
|
|---|
| 805 |
|
|---|
| 806 | }
|
|---|
| 807 |
|
|---|
| 808 | /*--------------------------------------------------------------------------
|
|---|
| 809 | * HYPRE_IJMatrixSetMaxOffProcElmts
|
|---|
| 810 | *--------------------------------------------------------------------------*/
|
|---|
| 811 |
|
|---|
| 812 | int
|
|---|
| 813 | HYPRE_IJMatrixSetMaxOffProcElmts( HYPRE_IJMatrix matrix,
|
|---|
| 814 | int max_off_proc_elmts)
|
|---|
| 815 | {
|
|---|
| 816 | hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
|---|
| 817 |
|
|---|
| 818 | if (!ijmatrix)
|
|---|
| 819 | {
|
|---|
| 820 | printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixSetMaxOffProcElmts\n");
|
|---|
| 821 | hypre_error_in_arg(1);
|
|---|
| 822 | return hypre_error_flag;
|
|---|
| 823 | }
|
|---|
| 824 |
|
|---|
| 825 | /* if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PETSC )
|
|---|
| 826 | return( hypre_IJMatrixSetMaxOffProcElmtsPETSc( ijmatrix ,
|
|---|
| 827 | max_off_proc_elmts_set, max_off_proc_elmts_add ) );
|
|---|
| 828 | else if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_ISIS )
|
|---|
| 829 | return( hypre_IJMatrixSetMaxOffProcElmtsISIS( ijmatrix ,
|
|---|
| 830 | max_off_proc_elmts_set, max_off_proc_elmts_add ) );
|
|---|
| 831 | else */
|
|---|
| 832 |
|
|---|
| 833 | if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
|
|---|
| 834 | return( hypre_IJMatrixSetMaxOffProcElmtsParCSR( ijmatrix ,
|
|---|
| 835 | max_off_proc_elmts) );
|
|---|
| 836 | else
|
|---|
| 837 | {
|
|---|
| 838 | printf("Unrecognized object type -- HYPRE_IJMatrixSetMaxOffProcElmts\n");
|
|---|
| 839 | hypre_error_in_arg(1);
|
|---|
| 840 | }
|
|---|
| 841 | return hypre_error_flag;
|
|---|
| 842 | }
|
|---|
| 843 |
|
|---|
| 844 | /*--------------------------------------------------------------------------
|
|---|
| 845 | * HYPRE_IJMatrixRead
|
|---|
| 846 | *--------------------------------------------------------------------------*/
|
|---|
| 847 |
|
|---|
| 848 | int
|
|---|
| 849 | HYPRE_IJMatrixRead( const char *filename,
|
|---|
| 850 | MPI_Comm comm,
|
|---|
| 851 | int type,
|
|---|
| 852 | HYPRE_IJMatrix *matrix_ptr )
|
|---|
| 853 | {
|
|---|
| 854 | HYPRE_IJMatrix matrix;
|
|---|
| 855 | HYPRE_BigInt ilower, iupper, jlower, jupper;
|
|---|
| 856 | HYPRE_BigInt I, J;
|
|---|
| 857 | int ncols;
|
|---|
| 858 | double value;
|
|---|
| 859 | int myid;
|
|---|
| 860 | char new_filename[255];
|
|---|
| 861 | FILE *file;
|
|---|
| 862 |
|
|---|
| 863 | MPI_Comm_rank(comm, &myid);
|
|---|
| 864 |
|
|---|
| 865 | sprintf(new_filename,"%s.%05d", filename, myid);
|
|---|
| 866 |
|
|---|
| 867 | if ((file = fopen(new_filename, "r")) == NULL)
|
|---|
| 868 | {
|
|---|
| 869 | printf("Error: can't open input file %s\n", new_filename);
|
|---|
| 870 |
|
|---|
| 871 | hypre_error_in_arg(1);
|
|---|
| 872 | return hypre_error_flag;
|
|---|
| 873 | }
|
|---|
| 874 |
|
|---|
| 875 | #ifdef HYPRE_LONG_LONG
|
|---|
| 876 | fscanf(file, "%lld %lld %lld %lld", &ilower, &iupper, &jlower, &jupper);
|
|---|
| 877 | #else
|
|---|
| 878 | fscanf(file, "%d %d %d %d", &ilower, &iupper, &jlower, &jupper);
|
|---|
| 879 | #endif
|
|---|
| 880 | HYPRE_IJMatrixCreate(comm, ilower, iupper, jlower, jupper, &matrix);
|
|---|
| 881 |
|
|---|
| 882 | HYPRE_IJMatrixSetObjectType(matrix, type);
|
|---|
| 883 | HYPRE_IJMatrixInitialize(matrix);
|
|---|
| 884 |
|
|---|
| 885 | ncols = 1;
|
|---|
| 886 | #ifdef HYPRE_LONG_LONG
|
|---|
| 887 | while ( fscanf(file, "%lld %lld %le", &I, &J, &value) != EOF )
|
|---|
| 888 | #else
|
|---|
| 889 | while ( fscanf(file, "%d %d %le", &I, &J, &value) != EOF )
|
|---|
| 890 | #endif
|
|---|
| 891 | {
|
|---|
| 892 | HYPRE_IJMatrixSetValues(matrix, 1, &ncols, &I, &J, &value);
|
|---|
| 893 | }
|
|---|
| 894 |
|
|---|
| 895 | HYPRE_IJMatrixAssemble(matrix);
|
|---|
| 896 |
|
|---|
| 897 | fclose(file);
|
|---|
| 898 |
|
|---|
| 899 | *matrix_ptr = matrix;
|
|---|
| 900 |
|
|---|
| 901 | return hypre_error_flag;
|
|---|
| 902 |
|
|---|
| 903 | }
|
|---|
| 904 |
|
|---|
| 905 | /*--------------------------------------------------------------------------
|
|---|
| 906 | * HYPRE_IJMatrixPrint
|
|---|
| 907 | *--------------------------------------------------------------------------*/
|
|---|
| 908 |
|
|---|
| 909 | int
|
|---|
| 910 | HYPRE_IJMatrixPrint( HYPRE_IJMatrix matrix,
|
|---|
| 911 | const char *filename )
|
|---|
| 912 | {
|
|---|
| 913 | MPI_Comm comm = hypre_IJMatrixComm(matrix);
|
|---|
| 914 | HYPRE_BigInt *row_partitioning;
|
|---|
| 915 | HYPRE_BigInt *col_partitioning;
|
|---|
| 916 | HYPRE_BigInt ilower, iupper, jlower, jupper;
|
|---|
| 917 | HYPRE_BigInt i, ii;
|
|---|
| 918 | int j;
|
|---|
| 919 | int ncols;
|
|---|
| 920 | HYPRE_BigInt *cols;
|
|---|
| 921 | double *values;
|
|---|
| 922 | int myid;
|
|---|
| 923 | char new_filename[255];
|
|---|
| 924 | FILE *file;
|
|---|
| 925 | void *object;
|
|---|
| 926 |
|
|---|
| 927 | if (!matrix)
|
|---|
| 928 | {
|
|---|
| 929 | printf("Variable matrix is NULL -- HYPRE_IJMatrixPrint\n");
|
|---|
| 930 | hypre_error_in_arg(1);
|
|---|
| 931 | return hypre_error_flag;
|
|---|
| 932 | }
|
|---|
| 933 |
|
|---|
| 934 | if ( (hypre_IJMatrixObjectType(matrix) != HYPRE_PARCSR) )
|
|---|
| 935 | {
|
|---|
| 936 | printf("Unrecognized object type -- HYPRE_IJMatrixPrint\n");
|
|---|
| 937 | hypre_error_in_arg(1);
|
|---|
| 938 | return hypre_error_flag;
|
|---|
| 939 | }
|
|---|
| 940 |
|
|---|
| 941 | MPI_Comm_rank(comm, &myid);
|
|---|
| 942 |
|
|---|
| 943 | sprintf(new_filename,"%s.%05d", filename, myid);
|
|---|
| 944 |
|
|---|
| 945 | if ((file = fopen(new_filename, "w")) == NULL)
|
|---|
| 946 | {
|
|---|
| 947 | printf("Error: can't open output file %s\n", new_filename);
|
|---|
| 948 | hypre_error_in_arg(2);
|
|---|
| 949 | return hypre_error_flag;
|
|---|
| 950 | }
|
|---|
| 951 |
|
|---|
| 952 | row_partitioning = hypre_IJMatrixRowPartitioning(matrix);
|
|---|
| 953 | col_partitioning = hypre_IJMatrixColPartitioning(matrix);
|
|---|
| 954 | #ifdef HYPRE_NO_GLOBAL_PARTITION
|
|---|
| 955 | ilower = row_partitioning[0];
|
|---|
| 956 | iupper = row_partitioning[1] - 1;
|
|---|
| 957 | jlower = col_partitioning[0];
|
|---|
| 958 | jupper = col_partitioning[1] - 1;
|
|---|
| 959 | #else
|
|---|
| 960 | ilower = row_partitioning[myid];
|
|---|
| 961 | iupper = row_partitioning[myid+1] - 1;
|
|---|
| 962 | jlower = col_partitioning[myid];
|
|---|
| 963 | jupper = col_partitioning[myid+1] - 1;
|
|---|
| 964 | #endif
|
|---|
| 965 | #ifdef HYPRE_LONG_LONG
|
|---|
| 966 | fprintf(file, "%lld %lld %lld %lld\n", ilower, iupper, jlower, jupper);
|
|---|
| 967 | #else
|
|---|
| 968 | fprintf(file, "%d %d %d %d\n", ilower, iupper, jlower, jupper);
|
|---|
| 969 | #endif
|
|---|
| 970 |
|
|---|
| 971 | HYPRE_IJMatrixGetObject(matrix, &object);
|
|---|
| 972 |
|
|---|
| 973 | for (i = ilower; i <= iupper; i++)
|
|---|
| 974 | {
|
|---|
| 975 | if ( hypre_IJMatrixObjectType(matrix) == HYPRE_PARCSR )
|
|---|
| 976 | {
|
|---|
| 977 | #ifdef HYPRE_NO_GLOBAL_PARTITION
|
|---|
| 978 | ii = i - hypre_IJMatrixGlobalFirstRow(matrix);
|
|---|
| 979 | #else
|
|---|
| 980 | ii = i - row_partitioning[0];
|
|---|
| 981 | #endif
|
|---|
| 982 | HYPRE_ParCSRMatrixGetRow((HYPRE_ParCSRMatrix) object,
|
|---|
| 983 | ii, &ncols, &cols, &values);
|
|---|
| 984 | for (j = 0; j < ncols; j++)
|
|---|
| 985 | {
|
|---|
| 986 | #ifdef HYPRE_NO_GLOBAL_PARTITION
|
|---|
| 987 | cols[j] += hypre_IJMatrixGlobalFirstCol(matrix);
|
|---|
| 988 | #else
|
|---|
| 989 | cols[j] += col_partitioning[0];
|
|---|
| 990 | #endif
|
|---|
| 991 | }
|
|---|
| 992 | }
|
|---|
| 993 |
|
|---|
| 994 | for (j = 0; j < ncols; j++)
|
|---|
| 995 | {
|
|---|
| 996 | #ifdef HYPRE_LONG_LONG
|
|---|
| 997 | fprintf(file, "%lld %lld %.14e\n", i, cols[j], values[j]);
|
|---|
| 998 | #else
|
|---|
| 999 | fprintf(file, "%d %d %.14e\n", i, cols[j], values[j]);
|
|---|
| 1000 | #endif
|
|---|
| 1001 | }
|
|---|
| 1002 |
|
|---|
| 1003 | if ( hypre_IJMatrixObjectType(matrix) == HYPRE_PARCSR )
|
|---|
| 1004 | {
|
|---|
| 1005 | for (j = 0; j < ncols; j++)
|
|---|
| 1006 | {
|
|---|
| 1007 | #ifdef HYPRE_NO_GLOBAL_PARTITION
|
|---|
| 1008 | cols[j] -= hypre_IJMatrixGlobalFirstCol(matrix);
|
|---|
| 1009 | #else
|
|---|
| 1010 | cols[j] -= col_partitioning[0];
|
|---|
| 1011 | #endif
|
|---|
| 1012 | }
|
|---|
| 1013 | HYPRE_ParCSRMatrixRestoreRow((HYPRE_ParCSRMatrix) object,
|
|---|
| 1014 | ii, &ncols, &cols, &values);
|
|---|
| 1015 | }
|
|---|
| 1016 | }
|
|---|
| 1017 |
|
|---|
| 1018 | fclose(file);
|
|---|
| 1019 |
|
|---|
| 1020 | return hypre_error_flag;
|
|---|
| 1021 | }
|
|---|