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,"
198 for (
int r = 0; r < size; r++)
200 std::sort(J + I[r], J + I[r+1]);
212 I.Wrap(newI, size+1,
true);
213 J.Wrap(newJ, I[size],
true);
218 MFEM_ASSERT( i >=0 && i<size,
"Index out of bounds. i = "<<i);
220 for (
int k = I[i], end = I[i+1]; k < end; k++)
233 MFEM_ABORT(
"Reached end of loop unexpectedly: (i,j) = (" << i <<
", " << j
241 int i, j, end, sum = 0, n = 0, newI = 0;
243 for (i=0; i<I[size]; i++)
255 for (i=0; i<size; i++)
258 for (j=I[i]; j<end; j++)
260 if (J[j] == -1) {
break; }
270 J.Wrap(NewJ, sum,
true);
272 MFEM_ASSERT(sum == n,
"sum = " << sum <<
", n = " << n);
281 int nnz = list.
Size();
286 for (
int i = 0, k = 0; i <= size; i++)
289 while (k < nnz && list[k].from == i)
299 int width = -1, nnz = (size >= 0) ? I[size] : 0;
300 for (
int k = 0; k < nnz; k++)
302 if (J[k] > width) { width = J[k]; }
311 for (i = 0; i < size; i++)
313 os <<
"[row " << i <<
"]\n";
314 for (j = I[i]; j < I[i+1]; j++)
316 os << setw(5) << J[j];
317 if ( !((j+1-I[i]) % width) )
322 if ((j-I[i]) % width)
333 for (i = 0; i < size; i++)
335 for (j = I[i]; j < I[i+1]; j++)
337 os << i <<
" " << J[j] <<
" 1. \n";
348 for (
int i = 0; i <= size; i++)
352 for (
int i = 0, nnz = I[size]; i < nnz; i++)
365 for (
int i = 0; i <= size; i++)
371 for (
int j = 0; j < nnz; j++)
400 if (size < 0 || I == NULL) {
return 0; }
401 return (size+1 + I[size]) *
sizeof(int);
412 const int *i_A = A.
GetI();
413 const int *j_A = A.
GetJ();
414 const int nrows_A = A.
Size();
415 const int ncols_A = (ncols_A_ < 0) ? A.
Width() : ncols_A_;
416 const int nnz_A = i_A[nrows_A];
420 int *i_At = At.
GetI();
421 int *j_At = At.
GetJ();
423 for (
int i = 0; i <= ncols_A; i++)
427 for (
int i = 0; i < nnz_A; i++)
431 for (
int i = 1; i < ncols_A; i++)
433 i_At[i+1] += i_At[i];
436 for (
int i = 0; i < nrows_A; i++)
438 for (
int j = i_A[i]; j < i_A[i+1]; j++)
440 j_At[i_At[j_A[j]]++] = i;
443 for (
int i = ncols_A; i > 0; i--)
459 At.
MakeI((ncols_A_ < 0) ? (A.
Max() + 1) : ncols_A_);
460 for (
int i = 0; i < A.
Size(); i++)
465 for (
int i = 0; i < A.
Size(); i++)
475 const int *i_A = A.
GetI();
476 const int *j_A = A.
GetJ();
477 const int *i_B = B.
GetI();
478 const int *j_B = B.
GetJ();
479 const int nrows_A = A.
Size();
480 const int nrows_B = B.
Size();
481 const int ncols_A = A.
Width();
482 const int ncols_B = B.
Width();
484 MFEM_VERIFY( ncols_A <= nrows_B,
"Table size mismatch: ncols_A = " << ncols_A
485 <<
", nrows_B = " << nrows_B);
489 for (i = 0; i < ncols_B; i++)
495 for (i = 0; i < nrows_A; i++)
497 for (j = i_A[i]; j < i_A[i+1]; j++)
500 for (l = i_B[k]; l < i_B[k+1]; l++)
503 if (B_marker[m] != i)
514 for (i = 0; i < ncols_B; i++)
522 for (i = 0; i < nrows_A; i++)
525 for (j = i_A[i]; j < i_A[i+1]; j++)
528 for (l = i_B[k]; l < i_B[k+1]; l++)
531 if (B_marker[m] != i)
551 Table(dim, connections_per_row)
581 Rows =
new Node*[nrows];
582 for (
int i = 0; i < nrows; i++)
590 int DSTable::Push_(
int r,
int c)
592 MFEM_ASSERT(r >= 0 && r < NumRows,
593 "Row out of bounds: r = " << r <<
", NumRows = " << NumRows);
595 for (n = Rows[r]; n != NULL; n = n->Prev)
602 #ifdef MFEM_USE_MEMALLOC
603 n = NodesMem.
Alloc ();
608 n->Index = NumEntries;
611 return (NumEntries++);
614 int DSTable::Index(
int r,
int c)
const
616 MFEM_ASSERT( r>=0,
"Row index must be non-negative, not "<<r);
621 for (Node *n = Rows[r]; n != NULL; n = n->Prev)
633 #ifdef MFEM_USE_MEMALLOC
636 for (
int i = 0; i < NumRows; i++)
638 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.
void Copy(Table ©) const
Table()
Creates an empty table.