47#ifdef HAVE_FEI_AZTECOO
58#define AZTEC_MPI AZTEC_MPI
66#include <az_blas_wrappers.h>
81 int tmp1 = data_org[AZ_N_internal];
82 int tmp2 = data_org[AZ_N_border];
83 length_ = tmp1 + tmp2 + data_org[AZ_N_external];
85 localCoeffs_ =
new double[length_];
91Aztec_LSVector::~Aztec_LSVector(){
92 delete [] localCoeffs_;
99Aztec_LSVector::Aztec_LSVector(
const Aztec_LSVector& source)
100 : amap_(source.amap_)
105 length_ = source.length_;
106 localCoeffs_ =
new double[length_];
111 Aztec_LSVector::operator=(source);
116double Aztec_LSVector::dotProd (
const Aztec_LSVector& y)
const {
120 int N_update = amap_->localSize();
122 double *pv = (
double*)localCoeffs_;
123 double *py = (
double*)y.startPointer();
125 double dot = AZ_gdot(N_update, pv, py, amap_->getProcConfig());
132void Aztec_LSVector::put(
double scalar) {
136 for (
int i = 0; i < length_; i++)
137 localCoeffs_[i] = scalar;
141void Aztec_LSVector::scale (
double s) {
145 int N_update = amap_->localSize();
148 DSCAL_F77(&N_update, &s, localCoeffs_, &one);
154void Aztec_LSVector::addVec (
double s,
const Aztec_LSVector& c) {
158 int N_update = amap_->localSize();
161 double *pv = localCoeffs_;
162 double *pc = (
double*)c.startPointer();
170double Aztec_LSVector::norm (
void)
const {
174 int N_update = amap_->localSize();
176 return(AZ_gvector_norm(N_update, 2,localCoeffs_, amap_->getProcConfig()));
180double Aztec_LSVector::norm1 (
void)
const {
184 int N_update = amap_->localSize();
186 return(AZ_gvector_norm(N_update, 1,localCoeffs_, amap_->getProcConfig()));
190double& Aztec_LSVector::operator [] (
int index) {
194 int offset = amap_->localOffset();
196 return(localCoeffs_[index - offset]);
200const double& Aztec_LSVector::operator [] (
int index)
const {
204 int offset = amap_->localOffset();
206 return(localCoeffs_[index - offset]);
210Aztec_LSVector* Aztec_LSVector::newVector()
const {
215 Aztec_LSVector* p =
new Aztec_LSVector(*
this);
221Aztec_LSVector& Aztec_LSVector::operator= (
const Aztec_LSVector& rhs) {
232void Aztec_LSVector::assign(
const Aztec_LSVector& rhs) {
234 if ((amap_->globalSize() != rhs.amap_->globalSize()) ||
235 (amap_->localSize() != rhs.amap_->localSize()) ) {
237 <<
" Aborting assignment." <<
FEI_ENDL;
241 int N_update = amap_->localSize();
242 double *pr = (
double*)rhs.startPointer();
244 for(
int i=0; i<N_update; ++i) {
245 localCoeffs_[i] = pr[i];
252bool Aztec_LSVector::readFromFile(
const char *fileName) {
261 int globalSize = amap_->globalSize();
269 if (fileName == NULL) {
274 if (strstr(fileName,
".txt") != NULL) {
278 fei::console_out() <<
"Aztec_LSVector::readFromFile: fileName doesn't contain "
279 <<
"'.txt', assuming binary data..." <<
FEI_ENDL;
283 FILE *file = fopen(fileName,
"r");
290 if (fread((
char *)&nn,
sizeof(
int),1,file) != 1)
291 throw "fei_Aztec_LSVector.cpp: I/O error.";
292 if (fread((
char *)&nnz,
sizeof(
int),1,file) != 1)
293 throw "fei_Aztec_LSVector.cpp: I/O error.";
297 if (fgets(line,128,file) == NULL)
298 throw "fei_Aztec_LSVector.cpp: I/O error.";
299 }
while(strchr(line,
'%'));
300 sscanf(line,
"%d",&nn);
302 if (nn != globalSize) {
309 int start = amap_->localOffset();
310 int end = start + amap_->localSize() - 1;
312 while (!feof(file)) {
314 if (fread((
char *)&i,
sizeof(
int),1,file) != 1)
315 throw "fei_Aztec_LSVector.cpp: I/O error.";
316 if (fread((
char *)&value,
sizeof(
double),1,file) != 1)
317 throw "fei_Aztec_LSVector.cpp: I/O error.";
320 if (fgets(line,128,file) == NULL)
321 throw "fei_Aztec_LSVector.cpp: I/O error.";
322 sscanf(line,
"%d %le",&i,&value);
326 if ((start <= i) && (i <= end)) {
327 localCoeffs_[i - start] = value;
335bool Aztec_LSVector::writeToFile(
const char *fileName)
const {
337 int N_update = amap_->localSize();
338 int start = amap_->localOffset();
339 int numProcs = amap_->getProcConfig()[AZ_N_procs];
340 int localRank = amap_->getProcConfig()[AZ_node];
342 MPI_Comm thisComm = amap_->getCommunicator();
352 if (masterRank == localRank){
354 file = fopen(fileName,
"w");
357 fprintf(file,
"%d\n",amap_->globalSize());
361 file = fopen(fileName,
"a");
365 for(i=0; i<N_update; i++) {
366 fprintf(file,
"%d %20.13e\n",start + i, localCoeffs_[i]);
void PREFIX DAXPY_F77(const int *n, const double *alpha, const double x[], const int *incx, double y[], const int *incy)
void PREFIX DSCAL_F77(const int *n, const double *alpha, double *x, const int *incx)
Aztec_LSVector(fei::SharedPtr< Aztec_Map > map, int *data_org)
std::ostream & console_out()
int numProcs(MPI_Comm comm)