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);
56 int i, j, sum = dim * connections_per_row;
63 for (i = 1; i <= size; i++)
65 I[i] = I[i-1] + connections_per_row;
66 for (j = I[i-1]; j < I[i]; j++) { J[j] = -1; }
77 for (
int i = 0; i < size; i++)
80 J[i] = partitioning[i];
89 for (
int i = 0; i <= nrows; i++)
99 for (k = i = 0; i < size; i++)
101 j = I[i], I[i] = k, k += j;
112 for (
int i = 0; i < nc; i++)
121 for (
int i = size; i > 0; i--)
130 SetDims (dim, dim * connections_per_row);
135 for (
int i = 0, j = 0; i < size; i++)
137 int end = I[i] + connections_per_row;
139 for ( ; j < end; j++) { J[j] = -1; }
148 j = (I) ? (I[size]) : (0);
153 (rows >= 0) ? I.New(rows+1) : I.Reset();
159 (nnz > 0) ? J.New(nnz) : J.Reset();
171 if ( i>=size || i<0 )
177 for (k = I[i]; k < end; k++)
193 MFEM_ASSERT(i >= 0 && i < size,
"Row index " << i <<
" is out of range [0,"
202 for (
int r = 0; r < size; r++)
204 std::sort(J + I[r], J + I[r+1]);
216 I.Wrap(newI, size+1,
true);
217 J.Wrap(newJ, I[size],
true);
222 MFEM_ASSERT( i >=0 && i<size,
"Index out of bounds. i = "<<i);
224 for (
int k = I[i], end = I[i+1]; k < end; k++)
237 MFEM_ABORT(
"Reached end of loop unexpectedly: (i,j) = (" << i <<
", " << j
245 int i, j, end, sum = 0, n = 0, newI = 0;
247 for (i=0; i<I[size]; i++)
257 int *NewJ =
new int[sum];
259 for (i=0; i<size; i++)
262 for (j=I[i]; j<end; j++)
264 if (J[j] == -1) {
break; }
274 J.Wrap(NewJ, sum,
true);
276 MFEM_ASSERT(sum == n,
"sum = " << sum <<
", n = " << n);
285 int nnz = list.
Size();
290 for (
int i = 0, k = 0; i <= size; i++)
293 while (k < nnz && list[k].from == i)
303 int width = -1, nnz = (size >= 0) ? I[size] : 0;
304 for (
int k = 0; k < nnz; k++)
306 if (J[k] > width) { width = J[k]; }
315 for (i = 0; i < size; i++)
317 out <<
"[row " << i <<
"]\n";
318 for (j = I[i]; j < I[i+1]; j++)
320 out << setw(5) << J[j];
321 if ( !((j+1-I[i]) % width) )
326 if ((j-I[i]) % width)
337 for (i = 0; i < size; i++)
339 for (j = I[i]; j < I[i+1]; j++)
341 out << i <<
" " << J[j] <<
" 1. \n";
352 for (
int i = 0; i <= size; i++)
356 for (
int i = 0, nnz = I[size]; i < nnz; i++)
369 for (
int i = 0; i <= size; i++)
375 for (
int j = 0; j < nnz; j++)
404 if (size < 0 || I == NULL) {
return 0; }
405 return (size+1 + I[size]) *
sizeof(int);
416 const int *i_A = A.
GetI();
417 const int *j_A = A.
GetJ();
418 const int nrows_A = A.
Size();
419 const int ncols_A = (_ncols_A < 0) ? A.
Width() : _ncols_A;
420 const int nnz_A = i_A[nrows_A];
424 int *i_At = At.
GetI();
425 int *j_At = At.
GetJ();
427 for (
int i = 0; i <= ncols_A; i++)
431 for (
int i = 0; i < nnz_A; i++)
435 for (
int i = 1; i < ncols_A; i++)
437 i_At[i+1] += i_At[i];
440 for (
int i = 0; i < nrows_A; i++)
442 for (
int j = i_A[i]; j < i_A[i+1]; j++)
444 j_At[i_At[j_A[j]]++] = i;
447 for (
int i = ncols_A; i > 0; i--)
463 At.
MakeI((_ncols_A < 0) ? (A.
Max() + 1) : _ncols_A);
464 for (
int i = 0; i < A.
Size(); i++)
469 for (
int i = 0; i < A.
Size(); i++)
479 const int *i_A = A.
GetI();
480 const int *j_A = A.
GetJ();
481 const int *i_B = B.
GetI();
482 const int *j_B = B.
GetJ();
483 const int nrows_A = A.
Size();
484 const int nrows_B = B.
Size();
485 const int ncols_A = A.
Width();
486 const int ncols_B = B.
Width();
488 MFEM_VERIFY( ncols_A <= nrows_B,
"Table size mismatch: ncols_A = " << ncols_A
489 <<
", nrows_B = " << nrows_B);
493 for (i = 0; i < ncols_B; i++)
499 for (i = 0; i < nrows_A; i++)
501 for (j = i_A[i]; j < i_A[i+1]; j++)
504 for (l = i_B[k]; l < i_B[k+1]; l++)
507 if (B_marker[m] != i)
518 for (i = 0; i < ncols_B; i++)
526 for (i = 0; i < nrows_A; i++)
529 for (j = i_A[i]; j < i_A[i+1]; j++)
532 for (l = i_B[k]; l < i_B[k+1]; l++)
535 if (B_marker[m] != i)
555 Table(dim, connections_per_row)
585 Rows =
new Node*[nrows];
586 for (
int i = 0; i < nrows; i++)
594 int DSTable::Push_(
int r,
int c)
596 MFEM_ASSERT(r >= 0 && r < NumRows,
597 "Row out of bounds: r = " << r <<
", NumRows = " << NumRows);
599 for (n = Rows[r]; n != NULL; n = n->Prev)
606 #ifdef MFEM_USE_MEMALLOC
607 n = NodesMem.
Alloc ();
612 n->Index = NumEntries;
615 return (NumEntries++);
618 int DSTable::Index(
int r,
int c)
const
620 MFEM_ASSERT( r>=0,
"Row index must be non-negative, not "<<r);
625 for (Node *n = Rows[r]; n != NULL; n = n->Prev)
637 #ifdef MFEM_USE_MEMALLOC
640 for (
int i = 0; i < NumRows; i++)
642 Node *na, *nb = Rows[i];
int Size() const
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 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 Transpose(const Table &A, Table &At, int _ncols_A)
Transpose a Table.
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 logical size of the array, keep existing entries.
void Load(std::istream &in)
void New(int size)
Allocate host memory for size entries with type MemoryType::HOST.
void SetIJ(int *newI, int *newJ, int newsize=-1)
Replace the I and J arrays with the given newI and newJ arrays.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
void Copy(Table ©) const
Table()
Creates an empty table.