int LOCA::Epetra::AugmentedOp::blockMap2PointMap(const Epetra_BlockMap& BlockMap, Epetra_Map*& PointMap) const { // Generate an Epetra_Map that has the same number and distribution of points // as the input Epetra_BlockMap object. The global IDs for the output PointMap // are computed by using the MaxElementSize of the BlockMap. For variable block // sizes this will create gaps in the GID space, but that is OK for Epetra_Maps. int MaxElementSize = BlockMap.MaxElementSize(); int PtNumMyElements = BlockMap.NumMyPoints(); int * PtMyGlobalElements = 0; if (PtNumMyElements>0) PtMyGlobalElements = new int[PtNumMyElements]; int NumMyElements = BlockMap.NumMyElements(); int curID = 0; for (int i=0; i<NumMyElements; i++) { int StartID = BlockMap.GID(i)*MaxElementSize; int ElementSize = BlockMap.ElementSize(i); for (int j=0; j<ElementSize; j++) PtMyGlobalElements[curID++] = StartID+j; } assert(curID==PtNumMyElements); // Sanity test PointMap = new Epetra_Map(-1, PtNumMyElements, PtMyGlobalElements, BlockMap.IndexBase(), BlockMap.Comm()); if (PtNumMyElements>0) delete [] PtMyGlobalElements; if (!BlockMap.PointSameAs(*PointMap)) {EPETRA_CHK_ERR(-1);} // Maps not compatible return(0); }
//========================================================================= int Ifpack_CrsRiluk::BlockMap2PointMap(const Epetra_BlockMap & BlockMap, Teuchos::RefCountPtr<Epetra_Map>* PointMap) { // Generate an Epetra_Map that has the same number and distribution of points // as the input Epetra_BlockMap object. The global IDs for the output PointMap // are computed by using the MaxElementSize of the BlockMap. For variable block // sizes this will create gaps in the GID space, but that is OK for Epetra_Maps. int MaxElementSize = BlockMap.MaxElementSize(); int PtNumMyElements = BlockMap.NumMyPoints(); vector<int> PtMyGlobalElements; if (PtNumMyElements>0) PtMyGlobalElements.resize(PtNumMyElements); int NumMyElements = BlockMap.NumMyElements(); int curID = 0; for (int i=0; i<NumMyElements; i++) { int StartID = BlockMap.GID(i)*MaxElementSize; int ElementSize = BlockMap.ElementSize(i); for (int j=0; j<ElementSize; j++) PtMyGlobalElements[curID++] = StartID+j; } assert(curID==PtNumMyElements); // Sanity test (*PointMap) = Teuchos::rcp( new Epetra_Map(-1, PtNumMyElements, &PtMyGlobalElements[0], BlockMap.IndexBase(), BlockMap.Comm()) ); if (!BlockMap.PointSameAs(*(*PointMap))) {EPETRA_CHK_ERR(-1);} // Maps not compatible return(0); }
Teuchos::RCP<Epetra_Map> mapDowncast(const Epetra_BlockMap &in) { if (in.ConstantElementSize() && in.ElementSize() == 1) { return Teuchos::rcp(new Epetra_Map(static_cast<const Epetra_Map &>(in))); } return Teuchos::null; }
int BlockMapToHandle(FILE * handle, const Epetra_BlockMap & map) { const Epetra_Comm & comm = map.Comm(); int numProc = comm.NumProc(); bool doSizes = !map.ConstantElementSize(); if (numProc==1) { int * myElements = map.MyGlobalElements(); int * elementSizeList = 0; if (doSizes) elementSizeList = map.ElementSizeList(); return(writeBlockMap(handle, map.NumGlobalElements(), myElements, elementSizeList, doSizes)); } int numRows = map.NumMyElements(); Epetra_Map allGidsMap(-1, numRows, 0,comm); Epetra_IntVector allGids(allGidsMap); for (int i=0; i<numRows; i++) allGids[i] = map.GID(i); Epetra_IntVector allSizes(allGidsMap); for (int i=0; i<numRows; i++) allSizes[i] = map.ElementSize(i); // Now construct a Map on PE 0 by strip-mining the rows of the input matrix map. int numChunks = numProc; int stripSize = allGids.GlobalLength()/numChunks; int remainder = allGids.GlobalLength()%numChunks; int curStart = 0; int curStripSize = 0; Epetra_IntSerialDenseVector importGidList; Epetra_IntSerialDenseVector importSizeList; if (comm.MyPID()==0) { importGidList.Size(stripSize+1); // Set size of vector to max needed if (doSizes) importSizeList.Size(stripSize+1); // Set size of vector to max needed } for (int i=0; i<numChunks; i++) { if (comm.MyPID()==0) { // Only PE 0 does this part curStripSize = stripSize; if (i<remainder) curStripSize++; // handle leftovers for (int j=0; j<curStripSize; j++) importGidList[j] = j + curStart; curStart += curStripSize; } // The following import map will be non-trivial only on PE 0. Epetra_Map importGidMap(-1, curStripSize, importGidList.Values(), 0, comm); Epetra_Import gidImporter(importGidMap, allGidsMap); Epetra_IntVector importGids(importGidMap); if (importGids.Import(allGids, gidImporter, Insert)) return(-1); Epetra_IntVector importSizes(importGidMap); if (doSizes) if (importSizes.Import(allSizes, gidImporter, Insert)) return(-1); // importGids (and importSizes, if non-trivial block map) // now have a list of GIDs (and sizes, respectively) for the current strip of map. int * myElements = importGids.Values(); int * elementSizeList = 0; if (doSizes) elementSizeList = importSizes.Values(); // Finally we are ready to write this strip of the map to file writeBlockMap(handle, importGids.MyLength(), myElements, elementSizeList, doSizes); } return(0); }
int checkmap(Epetra_BlockMap & Map, int NumGlobalElements, int NumMyElements, int *MyGlobalElements, int ElementSize, int * ElementSizeList, int NumGlobalPoints, int NumMyPoints, int IndexBase, Epetra_Comm& Comm, bool DistributedGlobal, bool IsOneToOne) { int i, ierr=0, forierr=0;// forierr is used in for loops, then is tested // after for loop completes to see if it is non zero - potentially prevents // thousands of error messages if (ElementSizeList==0) { EPETRA_TEST_ERR(!Map.ConstantElementSize(),ierr); } else EPETRA_TEST_ERR(Map.ConstantElementSize(),ierr); EPETRA_TEST_ERR(DistributedGlobal!=Map.DistributedGlobal(),ierr); EPETRA_TEST_ERR(IsOneToOne!=Map.IsOneToOne(),ierr); int *MyElementSizeList; if (ElementSizeList==0) { EPETRA_TEST_ERR(Map.ElementSize()!=ElementSize,ierr); MyElementSizeList = new int[NumMyElements]; EPETRA_TEST_ERR(Map.ElementSizeList(MyElementSizeList)!=0,ierr); forierr = 0; for (i=0; i<NumMyElements; i++) forierr += MyElementSizeList[i]!=ElementSize; EPETRA_TEST_ERR(forierr,ierr); EPETRA_TEST_ERR(Map.MaxMyElementSize() != ElementSize,ierr); EPETRA_TEST_ERR(Map.MinMyElementSize() != ElementSize,ierr); } else { MyElementSizeList = new int[NumMyElements]; EPETRA_TEST_ERR(Map.ElementSizeList(MyElementSizeList)!=0,ierr); int MaxSize = MyElementSizeList[0]; int MinSize = MyElementSizeList[0]; forierr=0; for (i=0; i<NumMyElements; i++) { forierr += MyElementSizeList[i]!=ElementSizeList[i]; if (MyElementSizeList[i] > MaxSize) MaxSize = MyElementSizeList[i]; if (MyElementSizeList[i] < MinSize) MinSize = MyElementSizeList[i]; // Test ElementSize(int LID) method forierr += Map.ElementSize(Map.LID(MyGlobalElements[i])) != ElementSizeList[i]; } EPETRA_TEST_ERR(forierr,ierr); EPETRA_TEST_ERR(MaxSize !=Map.MaxMyElementSize(),ierr); EPETRA_TEST_ERR(MinSize !=Map.MinMyElementSize(),ierr); } const Epetra_Comm & Comm1 = Map.Comm(); EPETRA_TEST_ERR(Comm1.NumProc()!=Comm.NumProc(),ierr); EPETRA_TEST_ERR(Comm1.MyPID()!=Comm.MyPID(),ierr); EPETRA_TEST_ERR(Map.IndexBase()!=IndexBase,ierr); EPETRA_TEST_ERR(!Map.LinearMap() && MyGlobalElements==0,ierr); EPETRA_TEST_ERR(Map.LinearMap() && MyGlobalElements!=0,ierr); EPETRA_TEST_ERR(Map.MaxAllGID()!=NumGlobalElements-1+IndexBase,ierr); EPETRA_TEST_ERR(Map.MaxElementSize()!=ElementSize,ierr); int MaxLID = Map.MaxLID(); EPETRA_TEST_ERR(MaxLID!=NumMyElements-1,ierr); int MaxMyGID = (Comm.MyPID()+1)*NumMyElements-1+IndexBase; if (Comm.MyPID()>2) MaxMyGID+=3; if (!DistributedGlobal) MaxMyGID = NumMyElements-1+IndexBase; EPETRA_TEST_ERR(Map.MaxMyGID()!=MaxMyGID,ierr); EPETRA_TEST_ERR(Map.MinAllGID()!=IndexBase,ierr); if (ElementSizeList==0) { EPETRA_TEST_ERR(Map.MinElementSize()!=ElementSize,ierr); } else EPETRA_TEST_ERR(Map.MinElementSize()!=2,ierr); int MinLID = Map.MinLID(); EPETRA_TEST_ERR(MinLID!=0,ierr); int MinMyGID = Comm.MyPID()*NumMyElements+IndexBase; if (Comm.MyPID()>2) MinMyGID+=3; if (!DistributedGlobal) MinMyGID = IndexBase; // Not really needed EPETRA_TEST_ERR(Map.MinMyGID()!=MinMyGID,ierr); int * MyGlobalElements1 = new int[NumMyElements]; EPETRA_TEST_ERR(Map.MyGlobalElements(MyGlobalElements1)!=0,ierr); forierr = 0; if (MyGlobalElements==0) { for (i=0; i<NumMyElements; i++) forierr += MyGlobalElements1[i]!=MinMyGID+i; EPETRA_TEST_ERR(forierr,ierr); } else { for (i=0; i<NumMyElements; i++) forierr += MyGlobalElements[i]!=MyGlobalElements1[i]; EPETRA_TEST_ERR(forierr,ierr); } EPETRA_TEST_ERR(Map.NumGlobalElements()!=NumGlobalElements,ierr); EPETRA_TEST_ERR(Map.NumGlobalPoints()!=NumGlobalPoints,ierr); EPETRA_TEST_ERR(Map.NumMyElements()!=NumMyElements,ierr); EPETRA_TEST_ERR(Map.NumMyPoints()!=NumMyPoints,ierr); int MaxMyGID2 = Map.GID(Map.LID(MaxMyGID)); EPETRA_TEST_ERR(MaxMyGID2 != MaxMyGID,ierr); int MaxLID2 = Map.LID(Map.GID(MaxLID)); EPETRA_TEST_ERR(MaxLID2 != MaxLID,ierr); EPETRA_TEST_ERR(Map.GID(MaxLID+1) != IndexBase-1,ierr);// MaxLID+1 doesn't exist EPETRA_TEST_ERR(Map.LID(MaxMyGID+1) != -1,ierr);// MaxMyGID+1 doesn't exist or is on a different processor EPETRA_TEST_ERR(!Map.MyGID(MaxMyGID),ierr); EPETRA_TEST_ERR(Map.MyGID(MaxMyGID+1),ierr); EPETRA_TEST_ERR(!Map.MyLID(MaxLID),ierr); EPETRA_TEST_ERR(Map.MyLID(MaxLID+1),ierr); EPETRA_TEST_ERR(!Map.MyGID(Map.GID(MaxLID)),ierr); EPETRA_TEST_ERR(Map.MyGID(Map.GID(MaxLID+1)),ierr); EPETRA_TEST_ERR(!Map.MyLID(Map.LID(MaxMyGID)),ierr); EPETRA_TEST_ERR(Map.MyLID(Map.LID(MaxMyGID+1)),ierr); // Test the FirstPointInElementList methods, begin by testing that they produce identical results int * FirstPointInElementList = new int[NumMyElements+1]; Map.FirstPointInElementList(FirstPointInElementList); int * FirstPointInElementList1 = Map.FirstPointInElementList(); forierr = 0; for (i=0; i<=NumMyElements; i++) forierr += FirstPointInElementList[i]!=FirstPointInElementList1[i]; EPETRA_TEST_ERR(forierr,ierr); // Now make sure values are correct forierr = 0; if (Map.ConstantElementSize()) { for (i=0; i<=NumMyElements; i++) forierr += FirstPointInElementList1[i]!=(i*ElementSize);// NOTE:FirstPointInElement[NumMyElements] is not the first point of an element EPETRA_TEST_ERR(forierr,ierr); } else { int FirstPoint = 0; for (i=0; i<NumMyElements; i++) { forierr += FirstPointInElementList1[i]!=FirstPoint; FirstPoint += ElementSizeList[i]; } EPETRA_TEST_ERR(forierr,ierr); EPETRA_TEST_ERR(FirstPointInElementList[NumMyElements] != NumMyPoints,ierr);// The last entry in the array = the total number of Points on the proc } delete [] FirstPointInElementList; // Declare some variables for the FindLocalElementID test int ElementID, Offset; // Test the PointToElementList methods, begin by testing that they produce identical results int * PointToElementList = new int[NumMyPoints]; Map.PointToElementList(PointToElementList); int * PointToElementList1 = Map.PointToElementList(); forierr = 0; for (i=0; i<NumMyPoints; i++) forierr += PointToElementList1[i] != PointToElementList[i]; EPETRA_TEST_ERR(forierr,ierr); //Now make sure values are correct forierr=0; if (Map.ConstantElementSize()) { for (i=0; i<NumMyElements; i++) for (int j=0; j<ElementSize; j++) { forierr += PointToElementList[i*ElementSize+j] != i; // Test FindLocalElementID method Map.FindLocalElementID(i*ElementSize+j,ElementID,Offset); forierr += ElementID != i || Offset != j; } EPETRA_TEST_ERR(forierr,ierr); } else { int MyPointTot = 0; // Keep track of total number of points in all previously completely checked elements for (i=0; i<NumMyElements; i++) { for (int j=0; j<ElementSizeList[i]; j++) { forierr += PointToElementList[MyPointTot+j] != i; // Test FindLocalElementID method Map.FindLocalElementID(MyPointTot+j,ElementID,Offset); forierr += ElementID != i || Offset != j; } MyPointTot += ElementSizeList[i]; } EPETRA_TEST_ERR(forierr,ierr); } delete [] PointToElementList; // Check RemoteIDList function that includes a parameter for size // Get some GIDs off of each processor to test int TotalNumEle, NumElePerProc, NumProc = Comm.NumProc(); int MinNumEleOnProc; int NumMyEle = Map.NumMyElements(); Comm.MinAll(&NumMyEle,&MinNumEleOnProc,1); if (MinNumEleOnProc > 5) NumElePerProc = 6; else NumElePerProc = MinNumEleOnProc; if (NumElePerProc > 0) { TotalNumEle = NumElePerProc*NumProc; int * MyGIDlist = new int[NumElePerProc]; int * GIDlist = new int[TotalNumEle]; int * PIDlist = new int[TotalNumEle]; int * LIDlist = new int[TotalNumEle]; int * SizeList = new int[TotalNumEle]; for (i=0; i<NumElePerProc; i++) MyGIDlist[i] = MyGlobalElements1[i]; Comm.GatherAll(MyGIDlist,GIDlist,NumElePerProc);// Get a few values from each proc Map.RemoteIDList(TotalNumEle, GIDlist, PIDlist, LIDlist, SizeList); int MyPID= Comm.MyPID(); forierr = 0; for (i=0; i<TotalNumEle; i++) { if (Map.MyGID(GIDlist[i])) { forierr += PIDlist[i] != MyPID; forierr += !Map.MyLID(Map.LID(GIDlist[i])) || Map.LID(GIDlist[i]) != LIDlist[i] || Map.GID(LIDlist[i]) != GIDlist[i]; forierr += SizeList[i] != Map.ElementSize(LIDlist[i]); } else { forierr += PIDlist[i] == MyPID; // If MyGID comes back false, the PID listed should be that of another proc } } EPETRA_TEST_ERR(forierr,ierr); delete [] MyGIDlist; delete [] GIDlist; delete [] PIDlist; delete [] LIDlist; delete [] SizeList; } delete [] MyGlobalElements1; delete [] MyElementSizeList; // Check RemoteIDList function (assumes all maps are linear, even if not stored that way) if (Map.LinearMap()) { int * GIDList = new int[3]; int * PIDList = new int[3]; int * LIDList = new int[3]; int MyPID = Map.Comm().MyPID(); int NumIDs = 0; //GIDList[NumIDs++] = Map.MaxAllGID()+1; // Should return -1 for both PID and LID if (Map.MinMyGID()-1>=Map.MinAllGID()) GIDList[NumIDs++] = Map.MinMyGID()-1; if (Map.MaxMyGID()+1<=Map.MaxAllGID()) GIDList[NumIDs++] = Map.MaxMyGID()+1; Map.RemoteIDList(NumIDs, GIDList, PIDList, LIDList); NumIDs = 0; //EPETRA_TEST_ERR(!(PIDList[NumIDs]==-1),ierr); //EPETRA_TEST_ERR(!(LIDList[NumIDs++]==-1),ierr); if (Map.MinMyGID()-1>=Map.MinAllGID()) EPETRA_TEST_ERR(!(PIDList[NumIDs++]==MyPID-1),ierr); if (Map.MaxMyGID()+1<=Map.MaxAllGID()) EPETRA_TEST_ERR(!(PIDList[NumIDs]==MyPID+1),ierr); if (Map.MaxMyGID()+1<=Map.MaxAllGID()) EPETRA_TEST_ERR(!(LIDList[NumIDs++]==0),ierr); delete [] GIDList; delete [] PIDList; delete [] LIDList; } return (ierr); }
//============================================================================== bool Epetra_BlockMap::SameAs(const Epetra_BlockMap & Map) const { // Quickest test: See if both maps share an inner data class if (this->BlockMapData_ == Map.BlockMapData_) return(true); if(!GlobalIndicesTypeMatch(Map)) return(false); // Next check other global properties that are easy global attributes if (BlockMapData_->MinAllGID_ != Map.MinAllGID64() || BlockMapData_->MaxAllGID_ != Map.MaxAllGID64() || BlockMapData_->NumGlobalElements_ != Map.NumGlobalElements64() || BlockMapData_->IndexBase_ != Map.IndexBase()) return(false); // Last possible global check for constant element sizes if (BlockMapData_->ConstantElementSize_ && BlockMapData_->ElementSize_!=Map.ElementSize()) return(false); // If we get this far, we need to check local properties and then check across // all processors to see if local properties are all true int numMyElements = BlockMapData_->NumMyElements_; int MySameMap = 1; // Assume not needed // First check if number of element is the same in each map if (numMyElements != Map.NumMyElements()) MySameMap = 0; // If numMyElements is the same, check to see that list of GIDs is the same if (MySameMap==1) { if (LinearMap() && Map.LinearMap() ) { // For linear maps, just need to check whether lower bound is the same if (MinMyGID64() != Map.MinMyGID64() ) MySameMap = 0; } else { for (int i = 0; i < numMyElements; i++) { if (GID64(i) != Map.GID64(i)) { MySameMap = 0; break; } } } } // for (int i = 0; i < numMyElements; i++) // if (GID64(i) != Map.GID64(i)) MySameMap = 0; // If GIDs are the same, check to see element sizes are the same if (MySameMap==1 && !BlockMapData_->ConstantElementSize_) { int * sizeList1 = ElementSizeList(); int * sizeList2 = Map.ElementSizeList(); for (int i = 0; i < numMyElements; i++) if (sizeList1[i] != sizeList2[i]) MySameMap=0; } // Now get min of MySameMap across all processors int GlobalSameMap = 0; int err = Comm().MinAll(&MySameMap, &GlobalSameMap, 1); assert(err==0); return(GlobalSameMap==1); }
int MultiVectorTests(const Epetra_BlockMap & Map, int NumVectors, bool verbose) { const Epetra_Comm & Comm = Map.Comm(); int ierr = 0, i; double *residual = new double[NumVectors]; Epetra_BLAS BLAS; /* get number of processors and the name of this processor */ // int NumProc = Comm.getNumProc(); int MyPID = Comm.MyPID(); // Construct MultiVectors Epetra_MultiVector A(Map, NumVectors); Epetra_MultiVector sqrtA(Map, NumVectors); Epetra_MultiVector B(Map, NumVectors); Epetra_MultiVector C(Map, NumVectors); Epetra_MultiVector C_alphaA(Map, NumVectors); Epetra_MultiVector C_alphaAplusB(Map, NumVectors); Epetra_MultiVector C_plusB(Map, NumVectors); Epetra_MultiVector Weights(Map, NumVectors); // Construct double vectors double *dotvec_AB = new double[NumVectors]; double *norm1_A = new double[NumVectors]; double *norm2_sqrtA = new double[NumVectors]; double *norminf_A = new double[NumVectors]; double *normw_A = new double[NumVectors]; double *minval_A = new double[NumVectors]; double *maxval_A = new double[NumVectors]; double *meanval_A = new double[NumVectors]; // Generate data EPETRA_TEST_ERR(C.Random(),ierr); // Fill C with random numbers. double alpha = 2.0; BuildMultiVectorTests (C,alpha, A, sqrtA, B, C_alphaA, C_alphaAplusB, C_plusB, dotvec_AB, norm1_A, norm2_sqrtA, norminf_A, normw_A, Weights, minval_A, maxval_A, meanval_A); int err = 0; if (verbose) cout << "XXXXX Testing alpha * A "; // Test alpha*A Epetra_MultiVector alphaA(A); // Copy of A EPETRA_TEST_ERR(alphaA.Scale(alpha),err); EPETRA_TEST_ERR(alphaA.Update(-1.0, C_alphaA, 1.0),err); EPETRA_TEST_ERR(alphaA.Norm2(residual),err); if (err) ierr += err; else { EPETRA_TEST_ERR(BadResidual(verbose,residual, NumVectors),ierr); } err = 0; if (verbose) cout << "XXXXX Testing C = alpha * A + B "; // Test alpha*A + B Epetra_MultiVector alphaAplusB(A); // Copy of A EPETRA_TEST_ERR(alphaAplusB.Update(1.0, B, alpha, A, 0.0),err); EPETRA_TEST_ERR(alphaAplusB.Update(-1.0, C_alphaAplusB, 1.0),err); EPETRA_TEST_ERR(alphaAplusB.Norm2(residual),err); if (err) ierr += err; else { EPETRA_TEST_ERR(BadResidual(verbose,residual, NumVectors),ierr); } err = 0; if (verbose) cout << "XXXXX Testing C += B "; // Test + B Epetra_MultiVector plusB(C); // Copy of C EPETRA_TEST_ERR(plusB.Update(1.0, B, 1.0),err); EPETRA_TEST_ERR(plusB.Update(-1.0, C_plusB, 1.0),err); EPETRA_TEST_ERR(plusB.Norm2(residual),err); if (err) ierr += err; else { EPETRA_TEST_ERR(BadResidual(verbose,residual, NumVectors),ierr); } err = 0; if (verbose) cout << "XXXXX Testing A.dotProd(B) "; // Test A.dotvec(B) double *dotvec = residual; EPETRA_TEST_ERR(A.Dot(B,dotvec),err); BLAS.AXPY(NumVectors,-1.0,dotvec_AB,dotvec); if (err) ierr += err; else { EPETRA_TEST_ERR(BadResidual(verbose,residual, NumVectors),ierr); } err = 0; if (verbose) cout << "XXXXX Testing norm1_A "; // Test A.norm1() double *norm1 = residual; EPETRA_TEST_ERR(A.Norm1(norm1),err); BLAS.AXPY(NumVectors,-1.0,norm1_A,norm1); if (err) ierr += err; else { EPETRA_TEST_ERR(BadResidual(verbose,residual, NumVectors),ierr); } err = 0; if (verbose) cout << "XXXXX Testing norm2_sqrtA "; // Test sqrtA.norm2() double *norm2 = residual; EPETRA_TEST_ERR(sqrtA.Norm2(norm2),err); BLAS.AXPY(NumVectors,-1.0,norm2_sqrtA,norm2); if (err) ierr += err; else { EPETRA_TEST_ERR(BadResidual(verbose,residual, NumVectors),ierr); } err = 0; if (verbose) cout << "XXXXX Testing norminf_A "; // Test A.norminf() double *norminf = residual; EPETRA_TEST_ERR(A.NormInf(norminf),err); BLAS.AXPY(NumVectors,-1.0,norminf_A,norminf); if (err) ierr += err; else { EPETRA_TEST_ERR(BadResidual(verbose,residual, NumVectors),ierr); } err = 0; if (verbose) cout << "XXXXX Testing normw_A "; // Test A.NormWeighted() double *normw = residual; EPETRA_TEST_ERR(A.NormWeighted(Weights, normw),err); BLAS.AXPY(NumVectors,-1.0,normw_A,normw); if (err) ierr += err; else { EPETRA_TEST_ERR(BadResidual(verbose,residual, NumVectors),ierr); } err = 0; if (verbose) cout << "XXXXX Testing minval_A "; // Test A.MinValue() double *minval = residual; EPETRA_TEST_ERR(A.MinValue(minval),err); BLAS.AXPY(NumVectors,-1.0,minval_A,minval); if (err) ierr += err; else { EPETRA_TEST_ERR(BadResidual(verbose,residual, NumVectors),ierr); } err = 0; if (verbose) cout << "XXXXX Testing maxval_A "; // Test A.MaxValue() double *maxval = residual; EPETRA_TEST_ERR(A.MaxValue(maxval),err); BLAS.AXPY(NumVectors,-1.0,maxval_A,maxval); if (err) ierr += err; else { EPETRA_TEST_ERR(BadResidual(verbose,residual, NumVectors),ierr); } err = 0; if (verbose) cout << "XXXXX Testing meanval_A "; // Test A.MeanValue() double *meanval = residual; EPETRA_TEST_ERR(A.MeanValue(meanval),err); BLAS.AXPY(NumVectors,-1.0,meanval_A,meanval); if (err) ierr += err; else { EPETRA_TEST_ERR(BadResidual(verbose,residual, NumVectors),ierr); } err = 0; if (verbose) cout << "XXXXX Testing abs_A "; // Test A.Abs() Epetra_MultiVector Abs_A = A; EPETRA_TEST_ERR(Abs_A.Abs(A),err); EPETRA_TEST_ERR(Abs_A.Update(1.0, A, -1.0),err); // Abs_A = A - Abs_A (should be zero since A > 0) EPETRA_TEST_ERR(Abs_A.Norm2(residual),err); if (err) ierr += err; else { EPETRA_TEST_ERR(BadResidual(verbose,residual, NumVectors),ierr); } err = 0; if (verbose) cout << "XXXXX Testing random_A (Test1) "; // Test A.Random() Epetra_MultiVector Rand1_A(A); Epetra_MultiVector Rand2_A(A); EPETRA_TEST_ERR(Rand1_A.Random(),err); EPETRA_TEST_ERR(Rand2_A.Random(),err); // Rand2_A = Rand1_A - Rand2_A (should be nonzero since Random() should give different vectors > 0) EPETRA_TEST_ERR(Rand2_A.Update(1.0, Rand1_A, -1.0),err); EPETRA_TEST_ERR(Rand2_A.Norm2(residual),err); if (err) ierr += err; else { EPETRA_TEST_ERR(BadResidual1(verbose,residual, NumVectors),ierr); } err = 0; if (verbose) cout << "XXXXX Testing random_A (Test2) "; // Next test that each column of the multivector is different from all other columns by testing the first value // of each vector against the first value of every other vector. int randvalsdiffer = 1; // Assume they all differ for (i=0; i< NumVectors; i++) for (int j=i+1; j<NumVectors; j++) if (Rand1_A[i][0]==Rand1_A[j][0]) randvalsdiffer = 0; // make false if equal int allrandvals = 0; Comm.MinAll(&randvalsdiffer, &allrandvals, 1); // get min of all values across all processors EPETRA_TEST_ERR(1-allrandvals, err); // If allrandvals is anything but 1, this will cause an error int locerr = err; Comm.MinAll(&locerr, &err, 1); if (verbose) { if (err==0) { cout << "\t Checked OK" << endl; } else { cout << "\t Checked Failed" << endl; } } err = 0; if (verbose) cout << "XXXXX Testing random_A (Test3) "; // Next test that the first element on each processor of the first column of Rand1_A is different from all others // First we will gather them all to PE 0 Epetra_Map RandstartsMap(-1, 1, 0, Comm); // This Map has a single element on each PE int itmp = 0; int nproc = Comm.NumProc(); if (MyPID==0) itmp = nproc; Epetra_Map AllrandstartsMap(nproc, itmp, 0, Comm); // Map has NumProc elements on PE 0, none elsewhere Epetra_MultiVector Randstarts(RandstartsMap, NumVectors); Epetra_MultiVector Allrandstarts(AllrandstartsMap, NumVectors); for (i=0; i< NumVectors; i++) Randstarts[i][0] = Rand1_A[i][0]; // Load first value of local multivector Epetra_Import Randimporter(AllrandstartsMap,RandstartsMap); EPETRA_TEST_ERR(Allrandstarts.Import(Randstarts,Randimporter,Insert),err); // cout << "Randstarts = " << Randstarts << endl << "Allrandstarts = " << Allrandstarts << endl; // Allrandstarts now contains the first values for each local section of Rand1_A. // Next test that this is true. randvalsdiffer = 1; // Assume they all differ if (MyPID==0) { for (i=0; i< NumVectors; i++) for (int irand=0; irand<nproc; irand++) for (int jrand=irand+1; jrand<nproc; jrand++) if (Allrandstarts[i][irand]==Allrandstarts[i][jrand]) randvalsdiffer = 0; // make false if equal } allrandvals = 0; Comm.MinAll(&randvalsdiffer, &allrandvals, 1); // get min of all values across all processors EPETRA_TEST_ERR(1-allrandvals, err); // If allrandvals is anything but 1, this will cause an error locerr = err; Comm.MinAll(&locerr, &err, 1); if (verbose) { if (err==0) { cout << "\t Checked OK" << endl; } else { cout << "\t Checked Failed" << endl; } } // Delete everything delete [] dotvec_AB; delete [] norm1_A; delete [] norm2_sqrtA; delete [] norminf_A; delete [] normw_A; delete [] minval_A; delete [] maxval_A; delete [] meanval_A; delete [] residual; //******************************************************************* // Post-construction modification tests //******************************************************************* if (verbose) cout << "\n\nXXXXX Testing Post-construction modification of a multivector" <<endl<<endl; err = 0; Epetra_MultiVector X(Map, NumVectors); X.Random(); // Pick middle range values for GID, LID and Vector Index int testGID = Map.NumGlobalElements()/2; int testVecIndex = NumVectors/2; int GIDSize = 1; int LIDOfGID = 0; int FirstEntryOfGID = 0; if (Map.MyGID(testGID)) { LIDOfGID = Map.LID(testGID); GIDSize = Map.ElementSize(LIDOfGID); FirstEntryOfGID = Map.FirstPointInElement(LIDOfGID); } // ======================================================================== // Test int ReplaceGlobalValue (int GlobalRow, int VectorIndex, double ScalarValue) // ======================================================================== double newGIDValue = 4.0; locerr = X.ReplaceGlobalValue(testGID, testVecIndex, newGIDValue); if (Map.MyGID(testGID)) { if (X[testVecIndex][FirstEntryOfGID]!=newGIDValue) err++; if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfGID<<"] = " << X[testVecIndex][FirstEntryOfGID] << " should = " << newGIDValue << endl; } else if (locerr!=1) err++; // Test for GID out of range error (=1) // ======================================================================== // Test int ReplaceGlobalValue (int GlobalRow, intBlockRowOffset, int VectorIndex, double ScalarValue) // ======================================================================== newGIDValue = 8.0; locerr = X.ReplaceGlobalValue(testGID, GIDSize-1, testVecIndex, newGIDValue); if (Map.MyGID(testGID)) { if (X[testVecIndex][FirstEntryOfGID+GIDSize-1]!=newGIDValue) err++; if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfGID+GIDSize-1<<"] = " << X[testVecIndex][FirstEntryOfGID+GIDSize-1] << " should = " << newGIDValue << endl; } else if (locerr!=1) err++; // Test for GID out of range error (=1) // ======================================================================== // Test int SumIntoGlobalValue (int GlobalRow, int VectorIndex, double ScalarValue) // ======================================================================== newGIDValue = 1.0; locerr = X.ReplaceGlobalValue(testGID, testVecIndex, newGIDValue); locerr = X.SumIntoGlobalValue(testGID, testVecIndex, newGIDValue); if (Map.MyGID(testGID)) { if (X[testVecIndex][FirstEntryOfGID]!=(newGIDValue+newGIDValue)) err++; if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfGID<<"] = " << X[testVecIndex][FirstEntryOfGID] << " should = " << newGIDValue << endl; } else if (locerr!=1) err++; // Test for GID out of range error (=1) // ======================================================================== // Test int SumIntoGlobalValue (int GlobalRow, intBlockRowOffset, int VectorIndex, double ScalarValue) // ======================================================================== newGIDValue = 1.0; locerr = X.ReplaceGlobalValue(testGID, GIDSize-1, testVecIndex, newGIDValue); locerr = X.SumIntoGlobalValue(testGID, GIDSize-1, testVecIndex, newGIDValue); if (Map.MyGID(testGID)) { if (X[testVecIndex][FirstEntryOfGID+GIDSize-1]!=(newGIDValue+newGIDValue)) err++; if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfGID+GIDSize-1<<"] = " << X[testVecIndex][FirstEntryOfGID+GIDSize-1] << " should = " << newGIDValue << endl; } else if (locerr!=1) err++; // Test for GID out of range error (=1) // ======================================================================== // Test Local "My" versions of same routine (less complicated) // ======================================================================== // Pick middle range values for LID int testLID = Map.NumMyElements()/2; int LIDSize = Map.ElementSize(testLID); int FirstEntryOfLID = Map.FirstPointInElement(testLID); double newLIDValue = 4.0; locerr = X.ReplaceMyValue(testLID, testVecIndex, newLIDValue); if (X[testVecIndex][FirstEntryOfLID]!=newLIDValue) err++; if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfLID<<"] = " << X[testVecIndex][FirstEntryOfLID] << " should = " << newLIDValue << endl; newLIDValue = 8.0; locerr = X.ReplaceMyValue(testLID, LIDSize-1, testVecIndex, newLIDValue); if (X[testVecIndex][FirstEntryOfLID+LIDSize-1]!=newLIDValue) err++; if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfLID+LIDSize-1<<"] = " << X[testVecIndex][FirstEntryOfLID+LIDSize-1] << " should = " << newLIDValue << endl; newLIDValue = 1.0; locerr = X.ReplaceMyValue(testLID, testVecIndex, newLIDValue); locerr = X.SumIntoMyValue(testLID, testVecIndex, newLIDValue); if (X[testVecIndex][FirstEntryOfLID]!=(newLIDValue+newLIDValue)) err++; if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfLID<<"] = " << X[testVecIndex][FirstEntryOfLID] << " should = " << newLIDValue << endl; newLIDValue = 2.0; locerr = X.ReplaceMyValue(testLID, LIDSize-1, testVecIndex, newLIDValue); locerr = X.SumIntoMyValue(testLID, LIDSize-1, testVecIndex, newLIDValue); if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfLID+LIDSize-1<<"] = " << X[testVecIndex][FirstEntryOfLID+LIDSize-1] << " should = " << newLIDValue << endl; if (X[testVecIndex][FirstEntryOfLID+LIDSize-1]!=(newLIDValue+newLIDValue)) err++; ierr += err; // ======================================================================== // Test Post-construction modification of an Epetra_Vector using a vector // our multivector X // ======================================================================== if (verbose) cout << "\n\nXXXXX Testing Post-construction modification of a vector" << endl << endl; Epetra_Vector * x = X(testVecIndex); int NumEntries = 2; double * VecValues = new double[NumEntries]; int * VecGIDs = new int[NumEntries]; VecGIDs[0] = testGID; VecGIDs[1] = testGID+1; // Some pathological chance that these GIDs are not valid // ======================================================================== // Test int ReplaceGlobalValues (int NumEntries, double *Values, int *Indices) // ======================================================================== VecValues[0] = 2.0; VecValues[1] = 4.0; locerr = x->ReplaceGlobalValues(NumEntries, VecValues, VecGIDs); for (i=0; i<NumEntries; i++) { testGID = VecGIDs[i]; if (Map.MyGID(testGID)) { LIDOfGID = Map.LID(testGID); GIDSize = EPETRA_MIN(GIDSize,Map.ElementSize(LIDOfGID)); // Need this value below FirstEntryOfGID = Map.FirstPointInElement(LIDOfGID); if ((*x)[FirstEntryOfGID]!=VecValues[i]) err++; if (verbose) cout << "x["<<FirstEntryOfGID<<"] = " << (*x)[FirstEntryOfGID] << " should = " << VecValues[i] << endl; } else if (locerr!=1) err++; // Test for GID out of range error (=1) } // ======================================================================== // Test int ReplaceGlobalValues (int NumEntries, int BlockOffset, double *Values, int *Indices) // ======================================================================== VecValues[0] = 4.0; VecValues[1] = 8.0; locerr = x->ReplaceGlobalValues(NumEntries, GIDSize-1, VecValues, VecGIDs); for (i=0; i<NumEntries; i++) { testGID = VecGIDs[i]; if (Map.MyGID(testGID)) { LIDOfGID = Map.LID(testGID); FirstEntryOfGID = Map.FirstPointInElement(LIDOfGID); if ((*x)[FirstEntryOfGID+GIDSize-1]!=VecValues[i]) err++; if (verbose) cout << "x["<<FirstEntryOfGID+GIDSize-1<<"] = " << (*x)[FirstEntryOfGID+GIDSize-1] << " should = " << VecValues[i] << endl; } else if (locerr!=1) err++; // Test for GID out of range error (=1) } // ======================================================================== // Test int SumIntoGlobalValues (int NumEntries, double *Values, int *Indices) // ======================================================================== VecValues[0] = 1.0; VecValues[1] = 2.0; locerr = x->ReplaceGlobalValues(NumEntries, VecValues, VecGIDs); locerr = x->SumIntoGlobalValues(NumEntries, VecValues, VecGIDs); for (i=0; i<NumEntries; i++) { testGID = VecGIDs[i]; if (Map.MyGID(testGID)) { LIDOfGID = Map.LID(testGID); FirstEntryOfGID = Map.FirstPointInElement(LIDOfGID); if ((*x)[FirstEntryOfGID]!=(VecValues[i]+VecValues[i])) err++; if (verbose) cout << "x["<<FirstEntryOfGID<<"] = " << (*x)[FirstEntryOfGID] << " should = " << (VecValues[i]+VecValues[i]) << endl; } else if (locerr!=1) err++; // Test for GID out of range error (=1) } // ======================================================================== // Test int ReplaceGlobalValues (int NumEntries, int BlockOffset, double *Values, int *Indices) // ======================================================================== VecValues[0] = 1.0; VecValues[1] = 2.0; locerr = x->ReplaceGlobalValues(NumEntries, GIDSize-1, VecValues, VecGIDs); locerr = x->SumIntoGlobalValues(NumEntries, GIDSize-1, VecValues, VecGIDs); for (i=0; i<NumEntries; i++) { testGID = VecGIDs[i]; if (Map.MyGID(testGID)) { LIDOfGID = Map.LID(testGID); FirstEntryOfGID = Map.FirstPointInElement(LIDOfGID); if ((*x)[FirstEntryOfGID+GIDSize-1]!=(VecValues[i]+VecValues[i])) err++; if (verbose) cout << "x["<<FirstEntryOfGID+GIDSize-1<<"] = " << (*x)[FirstEntryOfGID+GIDSize-1] << " should = " << (VecValues[i]+VecValues[i]) << endl; } else if (locerr!=1) err++; // Test for GID out of range error (=1) } // ======================================================================== // Test Local "My" versions of same routine (less complicated) // ======================================================================== int * VecLIDs = new int[NumEntries]; VecLIDs[0] = testLID; VecLIDs[1] = testLID+1; // Some pathological chance that these LIDs are not valid VecValues[0] = 2.0; VecValues[1] = 4.0; locerr = x->ReplaceMyValues(NumEntries, VecValues, VecLIDs); for (i=0; i<NumEntries; i++) { testLID = VecLIDs[i]; LIDSize = EPETRA_MIN(LIDSize,Map.ElementSize(testLID)); // Need this value below FirstEntryOfLID = Map.FirstPointInElement(testLID); if ((*x)[FirstEntryOfLID]!=VecValues[i]) err++; if (verbose) cout << "x["<<FirstEntryOfLID<<"] = " << (*x)[FirstEntryOfLID] << " should = " << VecValues[i] << endl; } VecValues[0] = 4.0; VecValues[1] = 8.0; locerr = x->ReplaceMyValues(NumEntries, LIDSize-1, VecValues, VecLIDs); for (i=0; i<NumEntries; i++) { testLID = VecLIDs[i]; LIDSize = EPETRA_MIN(LIDSize,Map.ElementSize(testLID)); // Need this value below FirstEntryOfLID = Map.FirstPointInElement(testLID); if ((*x)[FirstEntryOfLID+LIDSize-1]!=VecValues[i]) err++; if (verbose) cout << "x["<<FirstEntryOfLID+LIDSize-1<<"] = " << (*x)[FirstEntryOfLID+LIDSize-1] << " should = " << VecValues[i] << endl; } VecValues[0] = 1.0; VecValues[1] = 1.0; locerr = x->ReplaceMyValues(NumEntries, VecValues, VecLIDs); locerr = x->SumIntoMyValues(NumEntries, VecValues, VecLIDs); for (i=0; i<NumEntries; i++) { testLID = VecLIDs[i]; LIDSize = EPETRA_MIN(LIDSize,Map.ElementSize(testLID)); // Need this value below FirstEntryOfLID = Map.FirstPointInElement(testLID); if ((*x)[FirstEntryOfLID]!=(VecValues[i]+VecValues[i])) err++; if (verbose) cout << "x["<<FirstEntryOfLID<<"] = " << (*x)[FirstEntryOfLID] << " should = " << (VecValues[i]+VecValues[i]) << endl; } VecValues[0] = 2.0; VecValues[1] = 4.0; locerr = x->ReplaceMyValues(NumEntries, LIDSize-1, VecValues, VecLIDs); locerr = x->SumIntoMyValues(NumEntries, LIDSize-1, VecValues, VecLIDs); for (i=0; i<NumEntries; i++) { testLID = VecLIDs[i]; LIDSize = EPETRA_MIN(LIDSize,Map.ElementSize(testLID)); // Need this value below FirstEntryOfLID = Map.FirstPointInElement(testLID); if ((*x)[FirstEntryOfLID+LIDSize-1]!=(VecValues[i]+VecValues[i])) err++; if (verbose) cout << "x["<<FirstEntryOfLID+LIDSize-1<<"] = " << (*x)[FirstEntryOfLID+LIDSize-1] << " should = " << (VecValues[i]+VecValues[i]) << endl; } delete [] VecValues; delete [] VecGIDs; delete [] VecLIDs; return(ierr); }