44 #include <fei_trilinos_macros.hpp>
45 #include <fei_iostream.hpp>
47 #ifdef HAVE_FEI_AZTECOO
58 #define AZTEC_MPI AZTEC_MPI
66 #include <az_blas_wrappers.h>
68 #include <fei_SharedPtr.hpp>
69 #include <fei_Aztec_Map.hpp>
70 #include <fei_Aztec_LSVector.hpp>
72 namespace fei_trilinos {
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_];
91 Aztec_LSVector::~Aztec_LSVector(){
92 delete [] localCoeffs_;
99 Aztec_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);
116 double 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());
132 void Aztec_LSVector::put(
double scalar) {
136 for (
int i = 0; i < length_; i++)
137 localCoeffs_[i] = scalar;
141 void Aztec_LSVector::scale (
double s) {
145 int N_update = amap_->localSize();
148 DSCAL_F77(&N_update, &s, localCoeffs_, &one);
154 void 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();
164 DAXPY_F77(&N_update,&s,pc,&one,pv,&one);
170 double Aztec_LSVector::norm (
void)
const {
174 int N_update = amap_->localSize();
176 return(AZ_gvector_norm(N_update, 2,localCoeffs_, amap_->getProcConfig()));
180 double Aztec_LSVector::norm1 (
void)
const {
184 int N_update = amap_->localSize();
186 return(AZ_gvector_norm(N_update, 1,localCoeffs_, amap_->getProcConfig()));
190 double& Aztec_LSVector::operator [] (
int index) {
194 int offset = amap_->localOffset();
196 return(localCoeffs_[index - offset]);
200 const double& Aztec_LSVector::operator [] (
int index)
const {
204 int offset = amap_->localOffset();
206 return(localCoeffs_[index - offset]);
210 Aztec_LSVector* Aztec_LSVector::newVector()
const {
215 Aztec_LSVector* p =
new Aztec_LSVector(*
this);
221 Aztec_LSVector& Aztec_LSVector::operator= (
const Aztec_LSVector& rhs) {
232 void 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];
252 bool Aztec_LSVector::readFromFile(
const char *fileName) {
261 int globalSize = amap_->globalSize();
269 if (fileName == NULL) {
270 fei::console_out() <<
"Aztec_LSVector::readFromFile: ERROR, NULL fileName." << FEI_ENDL;
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");
285 fei::console_out() <<
"Aztec_LSVector: Error opening " << fileName << FEI_ENDL;
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) {
305 fei::console_out() <<
"amap_->globalSize():" << globalSize <<
" file n:" << nn << FEI_ENDL;
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;
335 bool 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();
344 for(p=0; p<numProcs; p++){
347 MPI_Barrier(thisComm);
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]);
std::ostream & console_out()
int numProcs(MPI_Comm comm)