hypre/distributed_matrix/distributed_matrix_ISIS.cc

222 lines
5.8 KiB
C++
Raw Normal View History

2006-08-01 06:54:37 +08:00
/*BHEADER**********************************************************************
* Copyright (c) 2007, Lawrence Livermore National Security, LLC.
2006-08-01 06:54:37 +08:00
* Produced at the Lawrence Livermore National Laboratory.
2006-09-23 06:06:21 +08:00
* Written by the HYPRE team. UCRL-CODE-222953.
2006-08-01 06:54:37 +08:00
* All rights reserved.
*
* This file is part of HYPRE (see http://www.llnl.gov/CASC/hypre/).
* Please see the COPYRIGHT_and_LICENSE file for the copyright notice,
2006-09-23 06:06:21 +08:00
* disclaimer, contact information and the GNU Lesser General Public License.
2006-08-01 06:54:37 +08:00
*
2006-09-23 06:06:21 +08:00
* HYPRE is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License (as published by the Free Software
* Foundation) version 2.1 dated February 1999.
2006-08-01 06:54:37 +08:00
*
2006-09-23 06:06:21 +08:00
* HYPRE is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the terms and conditions of the GNU General
* Public License for more details.
2006-08-01 06:54:37 +08:00
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Revision$
***********************************************************************EHEADER*/
2006-09-23 06:06:21 +08:00
/* THIS IS A C++ FILE, since it needs to call ISIS++ with objects */
#ifdef ISIS_AVAILABLE
#include "iostream.h"
#include "RowMatrix.h" // ISIS++ header file
#endif
#include "./distributed_matrix.h"
#ifdef ISIS_AVAILABLE
extern "C" {
typedef struct
{
int *ind;
double *val;
}
RowBuf;
#endif
/*--------------------------------------------------------------------------
* hypre_InitializeDistributedMatrixISIS
*--------------------------------------------------------------------------*/
/* matrix must be set before calling this function*/
int
hypre_InitializeDistributedMatrixISIS(hypre_DistributedMatrix *dm)
{
#ifdef ISIS_AVAILABLE
RowMatrix *mat = (RowMatrix *) hypre_DistributedMatrixLocalStorage(dm);
1998-03-06 02:04:54 +08:00
const Map& map = mat->getMap();
int num_rows = mat->getMap().n();
int num_cols = mat->getMap().n();
hypre_DistributedMatrixM(dm) = num_rows;
1998-03-06 02:04:54 +08:00
hypre_DistributedMatrixN(dm) = num_cols;
/* allocate space for row buffers */
RowBuf *rowbuf = new RowBuf;
1998-03-06 02:04:54 +08:00
rowbuf->ind = new int[num_cols];
rowbuf->val = new double[num_cols];
dm->auxiliary_data = (void *) rowbuf;
#endif
return 0;
}
/*--------------------------------------------------------------------------
* hypre_FreeDistributedMatrixISIS
*--------------------------------------------------------------------------*/
int
hypre_FreeDistributedMatrixISIS( hypre_DistributedMatrix *dm)
{
#ifdef ISIS_AVAILABLE
RowBuf *rowbuf = (RowBuf *) dm->auxiliary_data;
delete rowbuf->ind;
delete rowbuf->val;
delete rowbuf;
#endif
return 0;
}
/*--------------------------------------------------------------------------
* hypre_PrintDistributedMatrixISIS
*--------------------------------------------------------------------------*/
int
hypre_PrintDistributedMatrixISIS( hypre_DistributedMatrix *matrix )
{
#ifdef ISIS_AVAILABLE
cout << "hypre_PrintDistributedMatrixISIS not implemented" << endl;
#endif
return -1;
}
/*--------------------------------------------------------------------------
* hypre_GetDistributedMatrixLocalRangeISIS
*--------------------------------------------------------------------------*/
int
hypre_GetDistributedMatrixLocalRangeISIS( hypre_DistributedMatrix *dm,
int *start,
int *end )
{
#ifdef ISIS_AVAILABLE
RowMatrix *mat = (RowMatrix *) hypre_DistributedMatrixLocalStorage(dm);
*start = mat->getMap().startRow() - 1; // convert to 0-based
*end = mat->getMap().endRow(); // endRow actually returns 1 less
cout << "LocalRangeISIS " << *start << " " << *end << endl;
#endif
return 0;
}
/*--------------------------------------------------------------------------
* hypre_GetDistributedMatrixRowISIS
*--------------------------------------------------------------------------*/
/* semantics: buffers returned will be overwritten on next call to
// this get function */
int
hypre_GetDistributedMatrixRowISIS( hypre_DistributedMatrix *dm,
int row,
int *size,
int **col_ind,
double **values )
{
#ifdef ISIS_AVAILABLE
RowMatrix *mat = (RowMatrix *) hypre_DistributedMatrixLocalStorage(dm);
RowBuf *rowbuf;
int i, temp;
rowbuf = (RowBuf *) dm->auxiliary_data;
mat->getRow(row+1, temp, rowbuf->val, rowbuf->ind);
#if 0
// add diagonal element if necessary
{
int *p;
int found = 0;
for (i=0, p=rowbuf->ind; i<temp; i++, p++)
{
if (*p == row+1)
found = 1;
}
if (!found)
{
rowbuf->ind[temp] = row+1;
rowbuf->val[temp] = 1.; // pick a value
temp++;
}
}
#endif
// set pointers to local buffers
if (col_ind != NULL)
{
int *p;
*size = temp;
*col_ind = rowbuf->ind;
// need to convert to 0-based indexing for output
for (i=0, p=*col_ind; i<temp; i++, p++)
(*p)--;
}
if (values != NULL)
{
*values = rowbuf->val;
*size = temp;
}
#endif
return 0;
}
/*--------------------------------------------------------------------------
* hypre_RestoreDistributedMatrixRowISIS
*--------------------------------------------------------------------------*/
int
hypre_RestoreDistributedMatrixRowISIS( hypre_DistributedMatrix *dm,
int row,
int *size,
int **col_ind,
double **values )
{
/* does nothing, since we use local buffers */
return 0;
}
#ifdef ISIS_AVAILABLE
} // extern "C"
#endif