Arcane  4.2.1.0
Developer documentation
Loading...
Searching...
No Matches
BinaryToMatrixMarket.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/*---------------------------------------------------------------------------*/
9/*
10 * This file is based on the work on AMGCL library (version march 2026)
11 * which can be found at https://github.com/ddemidov/amgcl.
12 *
13 * Copyright (c) 2012-2022 Denis Demidov <dennis.demidov@gmail.com>
14 * SPDX-License-Identifier: MIT
15 */
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19#include "arccore/alina/AlinaUtils.h"
20#include "arccore/alina/Adapters.h"
21#include "arccore/alina/IO.h"
22
23#include "arccore/common/internal/ProgramOptions.h"
24
25#include <iostream>
26#include <string>
27
28int main(int argc, char* argv[])
29{
30 namespace po = Arcane::ProgramOptions;
31 namespace io = Arcane::Alina::IO;
32
33 using Arcane::Alina::precondition;
34
35 po::options_description desc("Options");
36
37 desc.add_options()("help,h", "Show this help.")("dense,d", po::bool_switch()->default_value(false),
38 "Matrix is dense.")("input,i", po::value<std::string>()->required(),
39 "Input binary file.")("output,o", po::value<std::string>()->required(),
40 "Output matrix in the MatrixMarket format.");
41
43 po::store(po::parse_command_line(argc, argv, desc), vm);
44
45 if (vm.count("help")) {
46 std::cout << desc << std::endl;
47 return 0;
48 }
49
50 po::notify(vm);
51
52 if (vm["dense"].as<bool>()) {
53 size_t n, m;
54 std::vector<double> v;
55
56 io::read_dense(vm["input"].as<std::string>(), n, m, v);
57 io::mm_write(vm["output"].as<std::string>(), v.data(), n, m);
58
59 std::cout
60 << "Wrote " << n << " by " << m << " dense matrix"
61 << std::endl;
62 }
63 else {
64 size_t n;
65 std::vector<ptrdiff_t> ptr, col;
66 std::vector<double> val;
67
68 io::read_crs(vm["input"].as<std::string>(), n, ptr, col, val);
69 io::mm_write(vm["output"].as<std::string>(), std::tie(n, ptr, col, val));
70
71 std::cout
72 << "Wrote " << n << " by " << n << " sparse matrix, "
73 << ptr.back() << " nonzeros" << std::endl;
74 }
75}
Describes a set of command-line options.
Stores parsed option values.