66 if (std::abs(Value) <
chopVal_)
return 0;
74 const int m = 2147483647;
80 int test = a * lo - r * hi;
91 const double Modulus = 2147483647.0;
92 const double DbleOne = 1.0;
93 const double DbleTwo = 2.0;
96 randdouble = DbleTwo * (randdouble / Modulus) - DbleOne;
115 int NumDoubleCompanions,
double ** DoubleCompanions,
116 int NumIntCompanions,
int ** IntCompanions,
117 int NumLongLongCompanions,
long long ** LongLongCompanions)
122 T *
const list = Keys;
127 for (
int j=0; j<max; j++)
129 for (
int k=j; k>=0; k-=m)
131 if ((SortAscending && list[k+m] >= list[k]) ||
132 ( !SortAscending && list[k+m] <= list[k]))
137 for (i=0; i<NumDoubleCompanions; i++) {
138 double dtemp = DoubleCompanions[i][k+m];
139 DoubleCompanions[i][k+m] = DoubleCompanions[i][k];
140 DoubleCompanions[i][k] = dtemp;
142 for (i=0; i<NumIntCompanions; i++) {
143 int itemp = IntCompanions[i][k+m];
144 IntCompanions[i][k+m] = IntCompanions[i][k];
145 IntCompanions[i][k] = itemp;
147 for (i=0; i<NumLongLongCompanions; i++) {
148 long long LLtemp = LongLongCompanions[i][k+m];
149 LongLongCompanions[i][k+m] = LongLongCompanions[i][k];
150 LongLongCompanions[i][k] = LLtemp;
159 int NumDoubleCompanions,
double ** DoubleCompanions,
160 int NumIntCompanions,
int ** IntCompanions,
161 int NumLongLongCompanions,
long long ** LongLongCompanions)
163 Sort<int>(SortAscending, NumKeys, Keys,
164 NumDoubleCompanions, DoubleCompanions,
165 NumIntCompanions, IntCompanions,
166 NumLongLongCompanions, LongLongCompanions);
170 int NumDoubleCompanions,
double ** DoubleCompanions,
171 int NumIntCompanions,
int ** IntCompanions,
172 int NumLongLongCompanions,
long long ** LongLongCompanions)
174 Sort<long long>(SortAscending, NumKeys, Keys,
175 NumDoubleCompanions, DoubleCompanions,
176 NumIntCompanions, IntCompanions,
177 NumLongLongCompanions, LongLongCompanions);
181 int NumDoubleCompanions,
double ** DoubleCompanions,
182 int NumIntCompanions,
int ** IntCompanions,
183 int NumLongLongCompanions,
long long ** LongLongCompanions)
185 Sort<double>(SortAscending, NumKeys, Keys,
186 NumDoubleCompanions, DoubleCompanions,
187 NumIntCompanions, IntCompanions,
188 NumLongLongCompanions, LongLongCompanions);
193 int NumDoubleCompanions,
double ** DoubleCompanions,
194 int NumIntCompanions,
int ** IntCompanions)
199 int *
const list = Keys;
204 for (
int j=0; j<max; j++)
206 for (
int k=j; k>=0; k-=m)
208 if ((SortAscending && list[k+m] >= list[k]) ||
209 ( !SortAscending && list[k+m] <= list[k]))
211 int temp = list[k+m];
214 for (i=0; i<NumDoubleCompanions; i++) {
215 double dtemp = DoubleCompanions[i][k+m];
216 DoubleCompanions[i][k+m] = DoubleCompanions[i][k];
217 DoubleCompanions[i][k] = dtemp;
219 for (i=0; i<NumIntCompanions; i++) {
220 int itemp = IntCompanions[i][k+m];
221 IntCompanions[i][k+m] = IntCompanions[i][k];
222 IntCompanions[i][k] = itemp;
231 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES // FIXME
235 bool high_rank_proc_owns_shared)
249 int* owner_procs =
new int[numMyElems];
252 0, 0, high_rank_proc_owns_shared);
256 int* myOwnedElems =
new int[numMyElems];
257 int numMyOwnedElems = 0;
259 for(
int i=0; i<numMyElems; ++i) {
260 int GID = myElems[i];
261 int owner = owner_procs[i];
263 if (myPID == owner) {
264 myOwnedElems[numMyOwnedElems++] = GID;
268 Epetra_Map one_to_one_map(-1, numMyOwnedElems, myOwnedElems,
271 delete [] myOwnedElems;
272 delete [] owner_procs;
275 return(one_to_one_map);
277 #endif // EPETRA_NO_32BIT_GLOBAL_INDICES
280 template<
typename int_type>
291 bool isRoot = usermap.
Comm().
MyPID()==root;
295 int globalquickreturn = 0;
303 usermap.
Comm().
MinAll(&quickreturn, &globalquickreturn, 1);
305 if (globalquickreturn==1) {
312 int numMyElements = 0;
313 if(usermap.
MaxAllGID64()+1 > std::numeric_limits<int>::max())
314 throw "Epetra_Util::Create_Root_Map: cannot fit all gids in int";
315 if (isRoot) numMyElements = (int)(usermap.
MaxAllGID64()+1);
321 throw usermap.
ReportError(
"usermap must have unique GIDs",-1);
327 Epetra_Map allGidsMap((int_type) -1, numMyElements, (int_type) 0, comm);
329 for (
int i=0; i<numMyElements; i++) allGids[i] = (int_type) usermap.
GID64(i);
331 if(usermap.
MaxAllGID64() > std::numeric_limits<int>::max())
332 throw "Epetra_Util::Create_Root_Map: cannot fit all gids in int";
335 int n1 = 0;
if (isRoot) n1 = numGlobalElements;
336 Epetra_Map allGidsOnRootMap((int_type) -1, n1, (int_type) 0, comm);
339 allGidsOnRoot.Import(allGids, importer,
Insert);
341 Epetra_Map rootMap((int_type)-1, allGidsOnRoot.MyLength(), allGidsOnRoot.Values(), (int_type)usermap.
IndexBase64(), comm);
345 int n1 = numGlobalElements;
349 allGidsOnRoot.Import(allGids, importer,
Insert);
351 Epetra_Map rootMap((int_type) -1, allGidsOnRoot.MyLength(), allGidsOnRoot.Values(), (int_type)usermap.
IndexBase64(), comm);
360 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
362 return TCreate_Root_Map<int>(usermap, root);
366 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
368 return TCreate_Root_Map<long long>(usermap, root);
372 throw "Epetra_Util::Create_Root_Map: GlobalIndices type unknown";
376 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
379 bool high_rank_proc_owns_shared)
395 int* owner_procs =
new int[numMyElems*2];
396 int* sizes = owner_procs+numMyElems;
399 0, sizes, high_rank_proc_owns_shared);
403 int* myOwnedElems =
new int[numMyElems*2];
404 int* ownedSizes = myOwnedElems+numMyElems;
405 int numMyOwnedElems = 0;
407 for(
int i=0; i<numMyElems; ++i) {
408 int GID = myElems[i];
409 int owner = owner_procs[i];
411 if (myPID == owner) {
412 ownedSizes[numMyOwnedElems] = sizes[i];
413 myOwnedElems[numMyOwnedElems++] = GID;
420 delete [] myOwnedElems;
421 delete [] owner_procs;
424 return(one_to_one_map);
426 #endif // EPETRA_NO_32BIT_GLOBAL_INDICES
428 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
431 bool high_rank_proc_owns_shared)
445 int* owner_procs =
new int[numMyElems*2];
446 int* sizes = owner_procs+numMyElems;
449 0, sizes, high_rank_proc_owns_shared);
453 long long* myOwnedElems =
new long long[numMyElems*2];
454 long long* ownedSizes = myOwnedElems+numMyElems;
455 int numMyOwnedElems = 0;
457 for(
int i=0; i<numMyElems; ++i) {
458 long long GID = myElems[i];
459 int owner = owner_procs[i];
461 if (myPID == owner) {
462 ownedSizes[numMyOwnedElems] = sizes[i];
463 myOwnedElems[numMyOwnedElems++] = GID;
467 Epetra_BlockMap one_to_one_map((
long long)-1, numMyOwnedElems, myOwnedElems,
470 delete [] myOwnedElems;
471 delete [] owner_procs;
474 return(one_to_one_map);
476 #endif // EPETRA_NO_64BIT_GLOBAL_INDICES
483 int nnz = CRS_rowptr[NumRows];
485 for(
int i = 0; i < NumRows; i++){
486 int start=CRS_rowptr[i];
487 if(start >= nnz)
continue;
489 double* locValues = &CRS_vals[start];
490 int NumEntries = CRS_rowptr[i+1] - start;
491 int* locIndices = &CRS_colind[start];
498 for(
int j = 0; j < max; j++) {
499 for(
int k = j; k >= 0; k-=m) {
500 if(locIndices[k+m] >= locIndices[k])
502 double dtemp = locValues[k+m];
503 locValues[k+m] = locValues[k];
504 locValues[k] = dtemp;
505 int itemp = locIndices[k+m];
506 locIndices[k+m] = locIndices[k];
507 locIndices[k] = itemp;
521 size_t nnz = CRS_rowptr[NumRows];
523 for(
int i = 0; i < NumRows; i++){
524 size_t start = CRS_rowptr[i];
525 if(start >= nnz)
continue;
527 double* locValues = &CRS_vals[start];
528 int NumEntries =
static_cast<int>(CRS_rowptr[i+1] - start);
529 int* locIndices = &CRS_colind[start];
536 for(
int j = 0; j < max; j++) {
537 for(
int k = j; k >= 0; k-=m) {
538 if(locIndices[k+m] >= locIndices[k])
540 double dtemp = locValues[k+m];
541 locValues[k+m] = locValues[k];
542 locValues[k] = dtemp;
543 int itemp = locIndices[k+m];
544 locIndices[k+m] = locIndices[k];
545 locIndices[k] = itemp;
560 int nnz = CRS_rowptr[NumRows];
561 int new_curr=CRS_rowptr[0], old_curr=CRS_rowptr[0];
563 for(
int i = 0; i < NumRows; i++){
564 int start=CRS_rowptr[i];
565 if(start >= nnz)
continue;
567 double* locValues = &CRS_vals[start];
568 int NumEntries = CRS_rowptr[i+1] - start;
569 int* locIndices = &CRS_colind[start];
577 for(
int j = 0; j < max; j++) {
578 for(
int k = j; k >= 0; k-=m) {
579 if(locIndices[k+m] >= locIndices[k])
581 double dtemp = locValues[k+m];
582 locValues[k+m] = locValues[k];
583 locValues[k] = dtemp;
584 int itemp = locIndices[k+m];
585 locIndices[k+m] = locIndices[k];
586 locIndices[k] = itemp;
593 for(
int j=CRS_rowptr[i]; j < CRS_rowptr[i+1]; j++) {
594 if(j > CRS_rowptr[i] && CRS_colind[j]==CRS_colind[new_curr-1]) {
595 CRS_vals[new_curr-1] += CRS_vals[j];
597 else if(new_curr==j) {
601 CRS_colind[new_curr] = CRS_colind[j];
602 CRS_vals[new_curr] = CRS_vals[j];
607 CRS_rowptr[i] = old_curr;
611 CRS_rowptr[NumRows] = new_curr;
621 size_t nnz = CRS_rowptr[NumRows];
622 size_t new_curr=CRS_rowptr[0], old_curr=CRS_rowptr[0];
624 for(
int i = 0; i < NumRows; i++){
625 size_t start=CRS_rowptr[i];
626 if(start >= nnz)
continue;
628 double* locValues = &CRS_vals[start];
629 int NumEntries =
static_cast<int>(CRS_rowptr[i+1] - start);
630 int* locIndices = &CRS_colind[start];
638 for(
int j = 0; j < max; j++) {
639 for(
int k = j; k >= 0; k-=m) {
640 if(locIndices[k+m] >= locIndices[k])
642 double dtemp = locValues[k+m];
643 locValues[k+m] = locValues[k];
644 locValues[k] = dtemp;
645 int itemp = locIndices[k+m];
646 locIndices[k+m] = locIndices[k];
647 locIndices[k] = itemp;
654 for(
size_t j=CRS_rowptr[i]; j < CRS_rowptr[i+1]; j++) {
655 if(j > CRS_rowptr[i] && CRS_colind[j]==CRS_colind[new_curr-1]) {
656 CRS_vals[new_curr-1] += CRS_vals[j];
658 else if(new_curr==j) {
662 CRS_colind[new_curr] = CRS_colind[j];
663 CRS_vals[new_curr] = CRS_vals[j];
668 CRS_rowptr[i] = old_curr;
672 CRS_rowptr[NumRows] = new_curr;
678 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
691 const int *RemoteLIDs = Importer.
RemoteLIDs();
702 if(use_minus_one_for_local)
703 for(i=0;i <N; i++) gpids[i]=std::make_pair(-1,Importer.
TargetMap().
GID(i));
705 for(i=0;i <N; i++) gpids[i]=std::make_pair(mypid,Importer.
TargetMap().
GID(i));
709 for(i=0,j=0;i<NumReceives;i++){
710 int pid=ProcsFrom[i];
711 for(k=0;k<LengthsFrom[i];k++){
712 if(pid!=mypid) gpids[RemoteLIDs[j]].first=pid;
728 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
741 const int *RemoteLIDs = Importer.
RemoteLIDs();
752 if(use_minus_one_for_local)
753 for(i=0;i <N; i++) gpids[i]=std::make_pair(-1,Importer.
TargetMap().
GID64(i));
755 for(i=0;i <N; i++) gpids[i]=std::make_pair(mypid,Importer.
TargetMap().
GID64(i));
759 for(i=0,j=0;i<NumReceives;i++){
760 int pid=ProcsFrom[i];
761 for(k=0;k<LengthsFrom[i];k++){
762 if(pid!=mypid) gpids[RemoteLIDs[j]].first=pid;
789 const int *RemoteLIDs = Importer.
RemoteLIDs();
800 if(use_minus_one_for_local)
801 for(i=0; i<N; i++) pids[i]=-1;
803 for(i=0; i<N; i++) pids[i]=mypid;
807 for(i=0,j=0;i<NumReceives;i++){
808 int pid=ProcsFrom[i];
809 for(k=0;k<LengthsFrom[i];k++){
810 if(pid!=mypid) pids[RemoteLIDs[j]]=pid;
829 RemotePIDs.resize(0);
834 RemotePIDs.resize(0);
850 for(i=0,j=0;i<NumReceives;i++){
851 int pid=ProcsFrom[i];
852 for(k=0;k<LengthsFrom[i];k++){
859 RemotePIDs.resize(0);
876 unsigned start = 0, end = len - 1;
878 while(end - start > 1) {
879 unsigned mid = (start + end) >> 1;
880 if (list[mid] < item) start = mid;
884 if (list[start] == item)
return(start);
885 if (list[end] == item)
return(end);
887 if (list[end] < item) {
892 if (list[start] < item) insertPoint = end;
893 else insertPoint = start;
903 return Epetra_Util_binary_search<int>(item, list, len, insertPoint);
908 const long long* list,
912 return Epetra_Util_binary_search<long long>(item, list, len, insertPoint);
928 unsigned start = 0, end = len - 1;
930 while(end - start > 1) {
931 unsigned mid = (start + end) >> 1;
932 if (aux_list[list[mid]] < item) start = mid;
936 if (aux_list[list[start]] == item)
return(start);
937 if (aux_list[list[end]] == item)
return(end);
939 if (aux_list[list[end]] < item) {
944 if (aux_list[list[start]] < item) insertPoint = end;
945 else insertPoint = start;
957 return Epetra_Util_binary_search_aux<int>(item, list, aux_list, len, insertPoint);
963 const long long* aux_list,
967 return Epetra_Util_binary_search_aux<long long>(item, list, aux_list, len, insertPoint);
975 int & M,
int & N,
int & nz,
int * & ptr,
976 int * & ind,
double * & val,
int & Nrhs,
977 double * & rhs,
int & ldrhs,
978 double * & lhs,
int & ldlhs) {
1018 for (
int i=0; i<M; i++) ptr[i+1] = ptr[i] + Graph.
NumMyIndices(i);
1026 template void Epetra_Util::Sort<int> (bool, int,
int *, int,
double **, int,
int **, int,
long long **);
1027 template void Epetra_Util::Sort<long long>(bool, int,
long long *, int,
double **, int,
int **, int,
long long **);
const int * LengthsFrom() const
Number of values we're receiving from each proc.
Epetra_MultiVector: A class for constructing and using dense multi-vectors, vectors and matrices in p...
long long MaxAllGID64() const
Epetra_Map: A class for partitioning vectors and matrices.
int NumRemoteIDs() const
Returns the number of elements that are not on the calling processor.
bool GlobalIndicesLongLong() const
Returns true if map create with long long NumGlobalElements.
unsigned int Seed() const
Get seed from Random function.
Epetra_Distributor: The Epetra Gather/Scatter Setup Base Class.
static Epetra_Map Create_OneToOne_Map(const Epetra_Map &usermap, bool high_rank_proc_owns_shared=false)
Epetra_Util Create_OneToOne_Map function.
int NumReceives() const
The number of procs from which we will receive data.
long long IndexBase64() const
int MyGlobalElements(int *MyGlobalElementList) const
Puts list of global elements on this processor into the user-provided array.
long long NumGlobalElements64() const
bool UniqueGIDs() const
Returns true if map GIDs are 1-to-1.
virtual Epetra_Directory * CreateDirectory(const Epetra_BlockMap &Map) const =0
Create a directory object for the given Epetra_BlockMap.
static const double chopVal_
#define EPETRA_CHK_ERR(a)
Epetra_Distributor & Distributor() const
bool GlobalIndicesInt() const
Returns true if map create with int NumGlobalElements.
MPI implementation of Epetra_Distributor.
virtual int MinAll(double *PartialMins, double *GlobalMins, int Count) const =0
Epetra_Comm Global Min function.
virtual int GetDirectoryEntries(const Epetra_BlockMap &Map, const int NumEntries, const int *GlobalEntries, int *Procs, int *LocalEntries, int *EntrySizes, bool high_rank_sharing_procs=false) const =0
GetDirectoryEntries : Returns proc and local id info for non-local map entries.
Epetra_Import: This class builds an import object for efficient importing of off-processor elements...
static int SortAndMergeCrsEntries(int NumRows, int *CRS_rowptr, int *CRS_colind, double *CRS_vals)
Epetra_Util SortAndMergeCrsEntries function.
static int GetPids(const Epetra_Import &Importer, std::vector< int > &pids, bool use_minus_one_for_local)
Epetra_Util GetPids function.
int NumVectors() const
Returns the number of vectors in the multi-vector.
virtual int MyPID() const =0
Return my process ID.
int MakeDataContiguous()
Eliminates memory that is used for construction. Make consecutive row index sections contiguous...
unsigned int RandomInt()
Returns a random integer on the interval (0, 2^31-1)
int IndexBase() const
Index base for this map.
int NumMyElements() const
Number of elements on the calling processor.
Epetra_Directory: This class is a pure virtual class whose interface allows Epetra_Map and Epetr_Bloc...
int NumMyCols() const
Returns the number of entries in the set of column-indices that appear on this processor.
static int GetPidGidPairs(const Epetra_Import &Importer, std::vector< std::pair< int, int > > &gpids, bool use_minus_one_for_local)
Epetra_Util GetPidGidPairs function.
long long GID64(int LID) const
static int SortCrsEntries(int NumRows, const int *CRS_rowptr, int *CRS_colind, double *CRS_vals)
Epetra_Util SortCrsEntries function.
int SetSeed(unsigned int Seed_in)
Set seed for Random function.
static Epetra_BlockMap Create_OneToOne_BlockMap(const Epetra_BlockMap &usermap, bool high_rank_proc_owns_shared=false)
Epetra_Util Create_OneToOne_Map function.
Epetra_Comm: The Epetra Communication Abstract Base Class.
const Epetra_BlockMap & TargetMap() const
Returns the TargetMap used to construct this importer.
static Epetra_Map Create_Root_Map(const Epetra_Map &usermap, int root=0)
Epetra_Util Create_Root_Map function.
int GID(int LID) const
Returns global ID of local ID, return IndexBase-1 if not found on this processor. ...
static Epetra_BlockMap Create_OneToOne_BlockMap64(const Epetra_BlockMap &usermap, bool high_rank_proc_owns_shared=false)
Epetra_Util Create_OneToOne_Map function for long long ordinals.
static Epetra_Map TCreate_Root_Map(const Epetra_Map &usermap, int root)
int NumMyRows() const
Returns the number of matrix rows owned by the calling processor.
Epetra_GIDTypeVector: A class for constructing and using dense "int" and "long long" vectors on a par...
Epetra_BlockMap: A class for partitioning block element vectors and matrices.
bool IndicesAreContiguous() const
If matrix indices are packed into single array (done in OptimizeStorage()) return true...
int Epetra_Util_binary_search_aux(T item, const int *list, const T *aux_list, int len, int &insertPoint)
Utility function to perform a binary-search on a list of data.
int Epetra_Util_binary_search(T item, const T *list, int len, int &insertPoint)
Utility function to perform a binary-search on a list of data.
const Epetra_Comm & Comm() const
Access function for Epetra_Comm communicator.
bool LinearMap() const
Returns true if the global ID space is contiguously divided (but not necessarily uniformly) across al...
int Stride() const
Returns the stride between vectors in the multi-vector (only meaningful if ConstantStride() is true)...
bool ConstantStride() const
Returns true if this multi-vector has constant stride between vectors.
int NumMyIndices(int Row) const
Returns the current number of nonzero entries in specified local row on this processor.
static int GetRemotePIDs(const Epetra_Import &Importer, std::vector< int > &RemotePIDs)
Epetra_Util GetRemotePIDs.
const int * ProcsFrom() const
A list of procs sending values to this proc.
virtual int NumProc() const =0
Returns total number of processes.
int * RemoteLIDs() const
List of elements in the target map that are coming from other processors.
double RandomDouble()
Returns a random double on the interval (-1.0,1.0)
Epetra_CrsMatrix: A class for constructing and using real-valued double-precision sparse compressed r...
static double Chop(const double &Value)
Epetra_Util Chop method. Return zero if input Value is less than ChopValue.
static void Sort(bool SortAscending, int NumKeys, T *Keys, int NumDoubleCompanions, double **DoubleCompanions, int NumIntCompanions, int **IntCompanions, int NumLongLongCompanions, long long **LongLongCompanions)
Epetra_Util Sort Routine (Shell sort)
virtual int ReportError(const std::string Message, int ErrorCode) const
Error reporting method.
const Epetra_Distributor * DistributorPtr() const
const Epetra_CrsGraph & Graph() const
Returns a reference to the Epetra_CrsGraph object associated with this matrix.
long long * MyGlobalElements64() const
Epetra_CrsGraph: A class for constructing and using sparse compressed row graphs. ...
Epetra_LocalMap: A class for replicating vectors and matrices across multiple processors.
int Epetra_Util_ExtractHbData(Epetra_CrsMatrix *A, Epetra_MultiVector *LHS, Epetra_MultiVector *RHS, int &M, int &N, int &nz, int *&ptr, int *&ind, double *&val, int &Nrhs, double *&rhs, int &ldrhs, double *&lhs, int &ldlhs)
Harwell-Boeing data extraction routine.
int NumMyNonzeros() const
Returns the number of nonzero entries in the calling processor's portion of the matrix.