File: render.cpp

package info (click to toggle)
librsb 1.3.0.2%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 32,792 kB
  • sloc: ansic: 274,405; f90: 108,468; cpp: 16,934; sh: 6,761; makefile: 1,679; objc: 692; awk: 22; sed: 1
file content (80 lines) | stat: -rw-r--r-- 2,059 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*

Copyright (C) 2020-2022 Michele Martone

This file is part of librsb.

librsb is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

librsb is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
License for more details.

You should have received a copy of the GNU Lesser General Public
License along with librsb; see the file COPYING.
If not, see <http://www.gnu.org/licenses/>.

*/
/*!
 \ingroup rsb_doc_examples
 @file
 @author Michele Martone

 @brief C++ example based on <rsb.hpp> of invoking the autotuner on an RsbMatrix matrix with RsbMatrix.tune_spmm() and rendering it with RsbMatrix.rndr().

 \include render.cpp
 */
#include <iostream>
#include <rsb.hpp>
#include <vector>
#include <string>
#include <sstream>
#if defined(_OPENMP)
#include <omp.h>
#endif

using namespace ::rsb;

template <typename NT=RSB_DEFAULT_TYPE>
void render_test(std::string filename="../A.mtx")
{
	RsbLib rsblib;
  	RsbMatrix<NT> mtx(filename.c_str());

#if defined(_OPENMP)
  	auto nt = omp_get_max_threads();
#else
	auto nt = 1;
#endif
	
	for ( ; nt > 0 ; nt /= 2 )
	{
		const rsb_trans_t transA { RSB_TRANSPOSITION_N };
  		rsblib.set_num_threads(nt);
		rsb_real_t sf{};
		rsb_int_t maxr = 0;
		rsb_time_t maxt = 0;
		const rsb_coo_idx_t nrhs {1};
		const rsb_flags_t order = RSB_FLAG_WANT_COLUMN_MAJOR_ORDER;
		std::ostringstream oss;
		oss << filename << "-" << nt << "th.eps";
		const auto psfilename = oss.str();

		mtx.tune_spmm(&sf,nullptr,maxr,maxt,transA, nullptr, nrhs, order, nullptr, {}, nullptr, nullptr, {});
		/*! [snip__RsbMatrix_rndr] */
		mtx.rndr(psfilename.c_str());
		/*! [snip__RsbMatrix_rndr] */
	}
}

auto main(const int argc, char * argv[]) -> int
{
	if(argc > 1)
		render_test(argv[1]);
	else
		render_test();
}