18 #include "../general/mem_manager.hpp"
32 const int nnz = table.
I[size];
35 I.CopyFrom(table.
I, size+1);
36 J.CopyFrom(table.
J, nnz);
52 int i, j, sum = dim * connections_per_row;
59 for (i = 1; i <= size; i++)
61 I[i] = I[i-1] + connections_per_row;
62 for (j = I[i-1]; j < I[i]; j++) { J[j] = -1; }
73 for (
int i = 0; i < size; i++)
76 J[i] = partitioning[i];
85 for (
int i = 0; i <= nrows; i++)
95 for (k = i = 0; i < size; i++)
97 j = I[i], I[i] = k, k += j;
108 for (
int i = 0; i < nc; i++)
117 for (
int i = size; i > 0; i--)
126 SetDims (dim, dim * connections_per_row);
131 for (
int i = 0, j = 0; i < size; i++)
133 int end = I[i] + connections_per_row;
135 for ( ; j < end; j++) { J[j] = -1; }
144 j = (I) ? (I[size]) : (0);
149 (rows >= 0) ? I.New(rows+1) : I.Reset();
155 (nnz > 0) ? J.New(nnz) : J.Reset();
167 if ( i>=size || i<0 )
173 for (k = I[i]; k < end; k++)
189 MFEM_ASSERT(i >= 0 && i < size,
"Row index " << i <<
" is out of range [0,"
201 for (
int r = 0; r < size; r++)
203 std::sort(J + I[r], J + I[r+1]);
215 I.Wrap(newI, size+1,
true);
216 J.Wrap(newJ, I[size],
true);
221 MFEM_ASSERT( i >=0 && i<size,
"Index out of bounds. i = "<<i);
223 for (
int k = I[i], end = I[i+1]; k < end; k++)
236 MFEM_ABORT(
"Reached end of loop unexpectedly: (i,j) = (" << i <<
", " << j
244 int i, j, end, sum = 0, n = 0, newI = 0;
246 for (i=0; i<I[size]; i++)
258 for (i=0; i<size; i++)
261 for (j=I[i]; j<end; j++)
263 if (J[j] == -1) {
break; }
273 J.Wrap(NewJ, sum,
true);
275 MFEM_ASSERT(sum == n,
"sum = " << sum <<
", n = " << n);
284 int nnz = list.
Size();
289 for (
int i = 0, k = 0; i <= size; i++)
292 while (k < nnz && list[k].from == i)
302 int width = -1, nnz = (size >= 0) ? I[size] : 0;
303 for (
int k = 0; k < nnz; k++)
305 if (J[k] > width) { width = J[k]; }
314 for (i = 0; i < size; i++)
316 os <<
"[row " << i <<
"]\n";
317 for (j = I[i]; j < I[i+1]; j++)
319 os << setw(5) << J[j];
320 if ( !((j+1-I[i]) % width) )
325 if ((j-I[i]) % width)
336 for (i = 0; i < size; i++)
338 for (j = I[i]; j < I[i+1]; j++)
340 os << i <<
" " << J[j] <<
" 1. \n";
351 for (
int i = 0; i <= size; i++)
355 for (
int i = 0, nnz = I[size]; i < nnz; i++)
368 for (
int i = 0; i <= size; i++)
374 for (
int j = 0; j < nnz; j++)
403 if (size < 0 || I == NULL) {
return 0; }
404 return (size+1 + I[size]) *
sizeof(int);
415 const int *i_A = A.
GetI();
416 const int *j_A = A.
GetJ();
417 const int nrows_A = A.
Size();
418 const int ncols_A = (ncols_A_ < 0) ? A.
Width() : ncols_A_;
419 const int nnz_A = i_A[nrows_A];
423 int *i_At = At.
GetI();
424 int *j_At = At.
GetJ();
426 for (
int i = 0; i <= ncols_A; i++)
430 for (
int i = 0; i < nnz_A; i++)
434 for (
int i = 1; i < ncols_A; i++)
436 i_At[i+1] += i_At[i];
439 for (
int i = 0; i < nrows_A; i++)
441 for (
int j = i_A[i]; j < i_A[i+1]; j++)
443 j_At[i_At[j_A[j]]++] = i;
446 for (
int i = ncols_A; i > 0; i--)
462 At.
MakeI((ncols_A_ < 0) ? (A.
Max() + 1) : ncols_A_);
463 for (
int i = 0; i < A.
Size(); i++)
468 for (
int i = 0; i < A.
Size(); i++)
478 const int *i_A = A.
GetI();
479 const int *j_A = A.
GetJ();
480 const int *i_B = B.
GetI();
481 const int *j_B = B.
GetJ();
482 const int nrows_A = A.
Size();
483 const int nrows_B = B.
Size();
484 const int ncols_A = A.
Width();
485 const int ncols_B = B.
Width();
487 MFEM_VERIFY( ncols_A <= nrows_B,
"Table size mismatch: ncols_A = " << ncols_A
488 <<
", nrows_B = " << nrows_B);
492 for (i = 0; i < ncols_B; i++)
498 for (i = 0; i < nrows_A; i++)
500 for (j = i_A[i]; j < i_A[i+1]; j++)
503 for (l = i_B[k]; l < i_B[k+1]; l++)
506 if (B_marker[m] != i)
517 for (i = 0; i < ncols_B; i++)
525 for (i = 0; i < nrows_A; i++)
528 for (j = i_A[i]; j < i_A[i+1]; j++)
531 for (l = i_B[k]; l < i_B[k+1]; l++)
534 if (B_marker[m] != i)
554 Table(dim, connections_per_row)
584 Rows =
new Node*[nrows];
585 for (
int i = 0; i < nrows; i++)
593 int DSTable::Push_(
int r,
int c)
595 MFEM_ASSERT(r >= 0 && r < NumRows,
596 "Row out of bounds: r = " << r <<
", NumRows = " << NumRows);
598 for (n = Rows[r]; n != NULL; n = n->Prev)
605 #ifdef MFEM_USE_MEMALLOC
606 n = NodesMem.
Alloc ();
611 n->Index = NumEntries;
614 return (NumEntries++);
617 int DSTable::Index(
int r,
int c)
const
619 MFEM_ASSERT( r>=0,
"Row index must be non-negative, not "<<r);
624 for (Node *n = Rows[r]; n != NULL; n = n->Prev)
636 #ifdef MFEM_USE_MEMALLOC
639 for (
int i = 0; i < NumRows; i++)
641 Node *na, *nb = Rows[i];
int Size() const
Return the logical size of the array.
void SetSize(int dim, int connections_per_row)
Set the size and the number of connections for the table.
int operator()(int i, int j) const
void MakeI(int nrows)
Next 7 methods are used together with the default constructor.
void SortRows()
Sort the column (TYPE II) indices in each row.
void Delete()
Delete the owned pointers and reset the Memory object.
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
void SetDims(int rows, int nnz)
void GetRow(int i, Array< int > &row) const
Return row i in array row (the Table must be finalized)
void Save(std::ostream &out) const
void AddConnections(int r, const int *c, int nc)
MemoryType GetMemoryType() const
Return a MemoryType that is currently valid. If both the host and the device pointers are currently v...
int Width() const
Returns the number of TYPE II elements (after Finalize() is called).
int operator()(int i, int j) const
void Print(std::ostream &out=mfem::out, int width=4) const
Prints the table to stream out.
void MakeFromList(int nrows, const Array< Connection > &list)
Table & operator=(const Table &rhs)
Assignment operator: deep copy.
void AddConnection(int r, int c)
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.
int Size() const
Returns the number of TYPE I elements.
void PrintMatlab(std::ostream &out) const
STable(int dim, int connections_per_row=3)
Creates table with fixed number of connections.
void Swap(Array< T > &, Array< T > &)
int size
size is the number of TYPE I elements.
void AddAColumnInRow(int r)
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
void Transpose(const Table &A, Table &At, int ncols_A_)
Transpose a Table.
void Load(std::istream &in)
void New(int size)
Allocate host memory for size entries with the current host memory type returned by MemoryManager::Ge...
void SetIJ(int *newI, int *newJ, int newsize=-1)
Replace the I and J arrays with the given newI and newJ arrays.
std::size_t MemoryUsage() const
void Copy(Table ©) const
Table()
Creates an empty table.