Skip to content

Commit 20991f4

Browse files
committed
dealii - drop extra copy on op inputs/outputs
1 parent 9e3c541 commit 20991f4

File tree

1 file changed

+12
-82
lines changed

1 file changed

+12
-82
lines changed

examples/deal.II/bps.h

Lines changed: 12 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,14 @@ class OperatorCeed : public OperatorBase<Number>
249249

250250
for (const auto i : dof_mapping)
251251
indices.emplace_back(
252-
partitioner->global_to_local(local_indices[fe.component_to_system_index(0, i)]) /
253-
n_components);
252+
partitioner->global_to_local(local_indices[fe.component_to_system_index(0, i)]));
254253
}
255254

256255
CeedElemRestrictionCreate(ceed,
257256
n_local_active_cells,
258257
fe.n_dofs_per_cell() / n_components,
259258
n_components,
260-
std::max<unsigned int>(this->extended_local_size() / n_components, 1),
259+
1,
261260
this->extended_local_size(),
262261
CEED_MEM_HOST,
263262
CEED_COPY_VALUES,
@@ -344,46 +343,18 @@ class OperatorCeed : public OperatorBase<Number>
344343
// communicate: update ghost values
345344
src.update_ghost_values();
346345

347-
if (dof_handler.get_fe().n_components() == 1)
348-
{
349-
// pass memory buffers to libCEED
350-
VectorTypeCeed x(src_ceed);
351-
VectorTypeCeed y(dst_ceed);
352-
x.import_array(src, CEED_MEM_HOST);
353-
y.import_array(dst, CEED_MEM_HOST);
354-
355-
// apply operator
356-
CeedOperatorApply(op_apply, x(), y(), CEED_REQUEST_IMMEDIATE);
357-
358-
// pull arrays back to deal.II
359-
x.sync_array();
360-
y.sync_array();
361-
}
362-
else // TODO: needed for multiple components
363-
{
364-
// allocate space for block vectors
365-
src_tmp.reinit(this->extended_local_size(), true);
366-
dst_tmp.reinit(this->extended_local_size(), true);
367-
368-
// copy to block vector
369-
copy_to_block_vector(src_tmp, src);
370-
371-
// pass memory buffers to libCEED
372-
VectorTypeCeed x(src_ceed);
373-
VectorTypeCeed y(dst_ceed);
374-
x.import_array(src_tmp, CEED_MEM_HOST);
375-
y.import_array(dst_tmp, CEED_MEM_HOST);
376-
377-
// apply operator
378-
CeedOperatorApply(op_apply, x(), y(), CEED_REQUEST_IMMEDIATE);
346+
// pass memory buffers to libCEED
347+
VectorTypeCeed x(src_ceed);
348+
VectorTypeCeed y(dst_ceed);
349+
x.import_array(src, CEED_MEM_HOST);
350+
y.import_array(dst, CEED_MEM_HOST);
379351

380-
// pull arrays back to deal.II
381-
x.sync_array();
382-
y.sync_array();
352+
// apply operator
353+
CeedOperatorApply(op_apply, x(), y(), CEED_REQUEST_IMMEDIATE);
383354

384-
// copy from block vector
385-
copy_from_block_vector(dst, dst_tmp);
386-
}
355+
// pull arrays back to deal.II
356+
x.sync_array();
357+
y.sync_array();
387358

388359
// communicate: compress
389360
src.zero_out_ghost_values();
@@ -419,17 +390,6 @@ class OperatorCeed : public OperatorBase<Number>
419390
// pull array back to deal.II
420391
y.sync_array();
421392

422-
const unsigned int n_components = dof_handler.get_fe().n_components();
423-
424-
if (n_components > 1) // TODO: needed for multiple components
425-
{
426-
VectorType tmp(diagonal);
427-
428-
copy_from_block_vector(tmp, diagonal);
429-
430-
std::swap(tmp, diagonal);
431-
}
432-
433393
diagonal.compress(VectorOperation::add);
434394

435395
for (auto &i : diagonal)
@@ -503,36 +463,6 @@ class OperatorCeed : public OperatorBase<Number>
503463
CeedVector vec_ceed;
504464
};
505465

506-
/**
507-
* Copy from block vector.
508-
*
509-
* @note Only needed for multiple components.
510-
*/
511-
void
512-
copy_from_block_vector(VectorType &dst, const VectorType &src) const
513-
{
514-
const unsigned int scalar_size = this->extended_local_size() / dim;
515-
516-
for (unsigned int i = 0; i < scalar_size; ++i)
517-
for (unsigned int j = 0; j < dim; ++j)
518-
dst.get_values()[j + i * dim] = src.get_values()[j * scalar_size + i];
519-
}
520-
521-
/**
522-
* Copy to block vector.
523-
*
524-
* @note Only needed for multiple components.
525-
*/
526-
void
527-
copy_to_block_vector(VectorType &dst, const VectorType &src) const
528-
{
529-
const unsigned int scalar_size = this->extended_local_size() / dim;
530-
531-
for (unsigned int i = 0; i < scalar_size; ++i)
532-
for (unsigned int j = 0; j < dim; ++j)
533-
dst.get_values()[j * scalar_size + i] = src.get_values()[j + i * dim];
534-
}
535-
536466
/**
537467
* Number of locally active DoFs.
538468
*/

0 commit comments

Comments
 (0)