32 const int nnz = table.
I[
size];
41 const Table &table2,
int offset)
43 MFEM_ASSERT(table1.
size == table2.
size,
44 "Tables have different sizes can not merge.");
47 const int nnz = table1.
I[
size] + table2.
I[
size];
53 for (
int i = 0; i <
size; i++)
58 for (
int r = 0; r < row.
Size(); r++,
I[i+1] ++)
64 for (
int r = 0; r < row.
Size(); r++,
I[i+1] ++)
66 J[
I[i+1] ] = (row[r] < 0) ? row[r] - offset : row[r] + offset;
73 const Table &table2,
int offset2,
74 const Table &table3,
int offset3)
76 MFEM_ASSERT(table1.
size == table2.
size,
77 "Tables have different sizes can not merge.");
78 MFEM_ASSERT(table1.
size == table3.
size,
79 "Tables have different sizes can not merge.");
88 for (
int i = 0; i <
size; i++)
93 for (
int r = 0; r < row.
Size(); r++,
I[i+1] ++)
99 for (
int r = 0; r < row.
Size(); r++,
I[i+1] ++)
101 J[
I[i+1] ] = (row[r] < 0) ? row[r] - offset2 : row[r] + offset2;
105 for (
int r = 0; r < row.
Size(); r++,
I[i+1] ++)
107 J[
I[i+1] ] = (row[r] < 0) ? row[r] - offset3 : row[r] + offset3;
124 int i, j, sum =
dim * connections_per_row;
131 for (i = 1; i <=
size; i++)
133 I[i] =
I[i-1] + connections_per_row;
134 for (j =
I[i-1]; j <
I[i]; j++) {
J[j] = -1; }
145 for (
int i = 0; i <
size; i++)
148 J[i] = partitioning[i];
157 for (
int i = 0; i <= nrows; i++)
167 for (k = i = 0; i <
size; i++)
169 j =
I[i],
I[i] = k, k += j;
180 for (
int i = 0; i < nc; i++)
189 for (
int i =
size; i > 0; i--)
203 for (
int i = 0, j = 0; i <
size; i++)
205 int end =
I[i] + connections_per_row;
207 for ( ; j < end; j++) {
J[j] = -1; }
216 j = (
I) ? (
I[
size]) : (0);
239 if ( i>=
size || i<0 )
245 for (k =
I[i]; k < end; k++)
261 MFEM_ASSERT(i >= 0 && i <
size,
"Row index " << i <<
" is out of range [0,"
273 for (
int r = 0; r <
size; r++)
275 std::sort(
J +
I[r],
J +
I[r+1]);
294 i<
size,
"Index out of bounds. i = " << i <<
" size " <<
size);
296 for (
int k =
I[i], end =
I[i+1]; k < end; k++)
309 MFEM_ABORT(
"Reached end of loop unexpectedly: (i,j) = (" << i <<
", " << j
317 int i, j, end, sum = 0, n = 0, newI = 0;
319 for (i=0; i<
I[
size]; i++)
331 for (i=0; i<
size; i++)
334 for (j=
I[i]; j<end; j++)
336 if (
J[j] == -1) {
break; }
346 J.
Wrap(NewJ, sum,
true);
348 MFEM_ASSERT(sum == n,
"sum = " << sum <<
", n = " << n);
357 int nnz = list.Size();
362 for (
int i = 0, k = 0; i <=
size; i++)
365 while (k < nnz && list[k].from == i)
375 int width = -1, nnz = (
size >= 0) ?
I[
size] : 0;
376 for (
int k = 0; k < nnz; k++)
378 if (
J[k] > width) { width =
J[k]; }
387 for (i = 0; i <
size; i++)
389 os <<
"[row " << i <<
"]\n";
390 for (j =
I[i]; j <
I[i+1]; j++)
392 os << setw(5) <<
J[j];
393 if ( !((j+1-
I[i]) % width) )
398 if ((j-
I[i]) % width)
409 for (i = 0; i <
size; i++)
411 for (j =
I[i]; j <
I[i+1]; j++)
413 os << i <<
" " <<
J[j] <<
" 1. \n";
424 for (
int i = 0; i <=
size; i++)
428 for (
int i = 0, nnz =
I[
size]; i < nnz; i++)
441 for (
int i = 0; i <=
size; i++)
447 for (
int j = 0; j < nnz; j++)
476 if (
size < 0 ||
I == NULL) {
return 0; }
488 const int *i_A = A.
GetI();
489 const int *j_A = A.
GetJ();
490 const int nrows_A = A.
Size();
491 const int ncols_A = (ncols_A_ < 0) ? A.
Width() : ncols_A_;
492 const int nnz_A = i_A[nrows_A];
496 int *i_At = At.
GetI();
497 int *j_At = At.
GetJ();
499 for (
int i = 0; i <= ncols_A; i++)
503 for (
int i = 0; i < nnz_A; i++)
507 for (
int i = 1; i < ncols_A; i++)
509 i_At[i+1] += i_At[i];
512 for (
int i = 0; i < nrows_A; i++)
514 for (
int j = i_A[i]; j < i_A[i+1]; j++)
516 j_At[i_At[j_A[j]]++] = i;
519 for (
int i = ncols_A; i > 0; i--)
535 At.
MakeI((ncols_A_ < 0) ? (A.
Max() + 1) : ncols_A_);
536 for (
int i = 0; i < A.
Size(); i++)
541 for (
int i = 0; i < A.
Size(); i++)
551 const int *i_A = A.
GetI();
552 const int *j_A = A.
GetJ();
553 const int *i_B = B.
GetI();
554 const int *j_B = B.
GetJ();
555 const int nrows_A = A.
Size();
556 const int nrows_B = B.
Size();
557 const int ncols_A = A.
Width();
558 const int ncols_B = B.
Width();
560 MFEM_VERIFY( ncols_A <= nrows_B,
"Table size mismatch: ncols_A = " << ncols_A
561 <<
", nrows_B = " << nrows_B);
565 for (i = 0; i < ncols_B; i++)
571 for (i = 0; i < nrows_A; i++)
573 for (j = i_A[i]; j < i_A[i+1]; j++)
576 for (l = i_B[k]; l < i_B[k+1]; l++)
579 if (B_marker[m] != i)
590 for (i = 0; i < ncols_B; i++)
598 for (i = 0; i < nrows_A; i++)
601 for (j = i_A[i]; j < i_A[i+1]; j++)
604 for (l = i_B[k]; l < i_B[k+1]; l++)
607 if (B_marker[m] != i)
657 Rows =
new Node*[nrows];
658 for (
int i = 0; i < nrows; i++)
666int DSTable::Push_(
int r,
int c)
668 MFEM_ASSERT(r >= 0 && r < NumRows,
669 "Row out of bounds: r = " << r <<
", NumRows = " << NumRows);
671 for (n = Rows[r]; n != NULL; n = n->Prev)
678#ifdef MFEM_USE_MEMALLOC
679 n = NodesMem.
Alloc ();
684 n->Index = NumEntries;
687 return (NumEntries++);
690int DSTable::Index(
int r,
int c)
const
692 MFEM_ASSERT( r>=0,
"Row index must be non-negative, not "<<r);
697 for (Node *n = Rows[r]; n != NULL; n = n->Prev)
709#ifdef MFEM_USE_MEMALLOC
712 for (
int i = 0; i < NumRows; i++)
714 Node *na, *nb = Rows[i];
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void Assign(const T *)
Copy data from a pointer. 'Size()' elements are copied.
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
int Size() const
Return the logical size of the array.
Class used by MFEM to store pointers to host and/or device memory.
MemoryType GetMemoryType() const
Return a MemoryType that is currently valid. If both the host and the device pointers are currently v...
void CopyFrom(const Memory &src, int size)
Copy size entries from src to *this.
void Reset()
Reset the memory to be empty, ensuring that Delete() will be a no-op.
void Wrap(T *ptr, int size, bool own)
Wrap an externally allocated host pointer, ptr with the current host memory type returned by MemoryMa...
void Delete()
Delete the owned pointers and reset the Memory object.
void New(int size)
Allocate host memory for size entries with the current host memory type returned by MemoryManager::Ge...
STable(int dim, int connections_per_row=3)
Creates table with fixed number of connections.
int operator()(int i, int j) const
Table & operator=(const Table &rhs)
Assignment operator: deep copy.
void Save(std::ostream &out) const
int size
size is the number of TYPE I elements.
const int * HostReadI() const
void AddConnections(int r, const int *c, int nc)
void PrintMatlab(std::ostream &out) const
void Load(std::istream &in)
int operator()(int i, int j) const
void SetSize(int dim, int connections_per_row)
Set the size and the number of connections for the table.
void GetRow(int i, Array< int > &row) const
Return row i in array row (the Table must be finalized)
void AddConnection(int r, int c)
void MakeI(int nrows)
Next 7 methods are used together with the default constructor.
void Print(std::ostream &out=mfem::out, int width=4) const
Prints the table to stream out.
void SetIJ(int *newI, int *newJ, int newsize=-1)
Replace the I and J arrays with the given newI and newJ arrays.
const int * HostReadJ() const
Table()
Creates an empty table.
int Size() const
Returns the number of TYPE I elements.
int Width() const
Returns the number of TYPE II elements (after Finalize() is called).
std::size_t MemoryUsage() const
void MakeFromList(int nrows, const Array< Connection > &list)
void Copy(Table ©) const
void AddAColumnInRow(int r)
void SortRows()
Sort the column (TYPE II) indices in each row.
void SetDims(int rows, int nnz)
void Swap(Array< T > &, Array< T > &)
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
void Transpose(const Table &A, Table &At, int ncols_A_)
Transpose a Table.