415 * stop_iteration_process,
nullptr);
417 * GKO_ENABLE_CRITERION_FACTORY(
ByInteraction, parameters, Factory);
421 *
bool check_impl(
gko::uint8 stoppingId,
bool setFinalized,
423 *
bool* one_changed,
const Criterion::Updater&)
override
425 *
bool result = *(parameters_.stop_iteration_process);
427 * this->set_all_statuses(stoppingId, setFinalized, stop_status);
428 * *one_changed =
true;
433 *
explicit ByInteraction(std::shared_ptr<const gko::Executor> exec)
434 * : EnablePolymorphicObject<ByInteraction, Criterion>(std::move(exec))
440 * : EnablePolymorphicObject<ByInteraction, Criterion>(
442 * parameters_{
factory->get_parameters()}
447 *
void run_solver(
volatile bool* stop_iteration_process,
448 * std::shared_ptr<gko::Executor> exec)
450 *
using ValueType = double;
452 *
using IndexType = int;
459 *
auto A =
share(gko::read<mtx>(std::ifstream(
"data/A.mtx"), exec));
460 *
auto b = gko::read<vec>(std::ifstream(
"data/b.mtx"), exec);
461 *
auto x = gko::read<vec>(std::ifstream(
"data/x0.mtx"), exec);
465 * .with_criteria(ByInteraction::build().with_stop_iteration_process(
466 * stop_iteration_process))
470 * gko::log::Logger::iteration_complete_mask, std::cout,
true));
473 * std::cout <<
"Solver stopped" << std::endl;
475 * std::cout <<
"Solution (x): \n";
476 *
write(std::cout, x);
478 *
auto one = gko::initialize<vec>({1.0}, exec);
479 *
auto neg_one = gko::initialize<vec>({-1.0}, exec);
480 *
auto res = gko::initialize<real_vec>({0.0}, exec);
481 * A->apply(
one, x, neg_one, b);
482 * b->compute_norm2(res);
484 * std::cout <<
"Residual norm sqrt(r^T r): \n";
485 *
write(std::cout, res);
489 *
int main(
int argc,
char* argv[])
493 *
if (argc == 2 && (std::string(argv[1]) ==
"--help")) {
494 * std::cerr <<
"Usage: " << argv[0] <<
" [executor]" << std::endl;
498 *
const auto executor_string = argc >= 2 ? argv[1] :
"reference";
500 * std::map<std::string, std::function<std::shared_ptr<gko::Executor>()>>
517 * {
"reference", [] {
return gko::ReferenceExecutor::create(); }}};
519 *
const auto exec = exec_map.at(executor_string)();
521 *
volatile bool stop_iteration_process{};
523 * std::thread t(run_solver, &stop_iteration_process, exec);
525 * std::cout <<
"Type 'stop' to stop the iteration process" << std::endl;
526 * std::string command;
527 *
while (std::cin >> command) {
528 *
if (command ==
"stop") {
531 * std::cout <<
"Unknown command" << std::endl;
534 * std::cout <<
"User input command 'stop' - The solver will stop!"
536 * stop_iteration_process =
true;
Definition custom-stopping-criterion.cpp:17
static std::shared_ptr< CudaExecutor > create(int device_id, std::shared_ptr< Executor > master, bool device_reset, allocation_mode alloc_mode=default_cuda_alloc_mode, CUstream_st *stream=nullptr)
static std::shared_ptr< DpcppExecutor > create(int device_id, std::shared_ptr< Executor > master, std::string device_type="all", dpcpp_queue_property property=dpcpp_queue_property::in_order)
Definition polymorphic_object.hpp:668
static std::shared_ptr< HipExecutor > create(int device_id, std::shared_ptr< Executor > master, bool device_reset, allocation_mode alloc_mode=default_hip_alloc_mode, CUstream_st *stream=nullptr)
static std::shared_ptr< OmpExecutor > create(std::shared_ptr< CpuAllocatorBase > alloc=std::make_shared< CpuAllocator >())
Definition executor.hpp:1396
Definition bicgstab.hpp:53
Definition criterion.hpp:36
static const version_info & get()
Definition version.hpp:139
#define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name)
Definition abstract_factory.hpp:280
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Definition abstract_factory.hpp:445
#define GKO_ENABLE_BUILD_METHOD(_factory_name)
Definition abstract_factory.hpp:394
constexpr T one()
Definition math.hpp:630
std::uint8_t uint8
Definition types.hpp:118
void write(StreamType &&os, MatrixPtrType &&matrix, layout_type layout=detail::mtx_io_traits< std::remove_cv_t< detail::pointee< MatrixPtrType > > >::default_layout)
Definition mtx_io.hpp:295
detail::shared_type< OwningPointer > share(OwningPointer &&p)
Definition utils_helper.hpp:224
typename detail::remove_complex_s< T >::type remove_complex
Definition math.hpp:260
Definition criterion.hpp:205