<commit_before>// This example computes the eigenvalues of largest magnitude of an
// eigenvalue problem $A x = \lambda x$, using Anasazi's
// implementation of the Block Davidson method.

// Include header for block Davidson eigensolver
#include "AnasaziBlockDavidsonSolMgr.hpp"
// Include header to define eigenproblem Ax = \lambda*x
#include "AnasaziBasicEigenproblem.hpp"
#include "AnasaziOperator.hpp"
#include "FM_MultiVector.h"

#include "sparse_matrix.h"

// ****************************************************************************
// BEGIN MAIN ROUTINE
// ****************************************************************************

using namespace fm;

std::atomic<size_t> iter_no;

class FM_Operator//: public Anasazi::Operator<double>
{
	sparse_matrix::ptr mat;
public:
	FM_Operator(sparse_matrix::ptr mat) {
		this->mat = mat;
	}

	virtual void Apply(const FM_MultiVector<double>& x,
			FM_MultiVector<double>& y) const {
		printf("SpMM: y(%s) = A * x(%s)\n", y.get_name().c_str(), x.get_name().c_str());
		block_multi_vector::sparse_matrix_multiply<double>(*mat, *x.get_data(),
				*y.get_data());
		y.sync_fm2ep();

//		assert((size_t) x.GetGlobalLength() == mat->get_num_cols());
//		assert((size_t) y.GetGlobalLength() == mat->get_num_rows());
//		mem_vector::ptr in = mem_vector::create(mat->get_num_cols(),
//				get_scalar_type<double>());
//		mem_vector::ptr out = mem_vector::create(mat->get_num_rows(),
//				get_scalar_type<double>());
//		for (int i = 0; i < x.GetNumberVecs(); i++) {
//			memcpy(in->get_raw_arr(), x.get_ep_mv()[i], in->get_length() * sizeof(double));
//			out->reset_data();
//			mat->multiply<double>(*in, *out);
//			memcpy(y.get_ep_mv()[i], out->get_raw_arr(), out->get_length() * sizeof(double));
//		}
//		y.sync_ep2fm();
	}

	size_t get_num_cols() const {
		return mat->get_num_cols();
	}

	size_t get_num_rows() const {
		return mat->get_num_rows();
	}
};

namespace Anasazi
{

template<>
class OperatorTraits <double, FM_MultiVector<double>, FM_Operator>
{
public:
	/*! \brief This method takes the FM_MultiVector \c x and
	 * applies the FM_Operator \c Op to it resulting in the FM_MultiVector \c y.
	 */
	static void Apply ( const FM_Operator& Op,
			const FM_MultiVector<double>& x, FM_MultiVector<double>& y ) {
		iter_no++;
		Op.Apply(x,y);
	}

};

}

int
main (int argc, char *argv[])
{
	using Teuchos::RCP;
	using Teuchos::rcp;
	using std::cerr;
	using std::cout;
	using std::endl;

	if (argc < 5) {
		fprintf(stderr, "eigensolver conf_file graph_file index_file nev\n");
		exit(1);
	}

	std::string conf_file = argv[1];
	std::string graph_file = argv[2];
	std::string index_file = argv[3];
	int nev = atoi(argv[4]); // number of eigenvalues for which to solve

	// Anasazi solvers have the following template parameters:
	//
	//   - Scalar: The type of dot product results.
	//   - MV: The type of (multi)vectors.
	//   - OP: The type of operators (functions from multivector to
	//     multivector).  A matrix (like Epetra_CrsMatrix) is an example
	//     of an operator; an Ifpack preconditioner is another example.
	//
	// Here, Scalar is double, MV is FM_MultiVector, and OP is FM_Operator.
	typedef FM_MultiVector<double> MV;
	typedef FM_Operator OP;
	typedef Anasazi::MultiVecTraits<double, MV> MVT;

	//
	// Set up the test problem.
	//
	config_map::ptr configs = config_map::create(conf_file);
	init_flash_matrix(configs);

	fg::FG_graph::ptr fg = fg::FG_graph::create(graph_file, index_file, configs);
	sparse_matrix::ptr m = sparse_matrix::create(fg);
	RCP<FM_Operator> A = rcp(new FM_Operator(m));

	// Set eigensolver parameters.
	const double tol = 1.0e-8; // convergence tolerance
	const int blockSize = nev + 1; // block size (number of eigenvectors processed at once)
	const int numBlocks = 8; // restart length
	const int maxRestarts = 100; // maximum number of restart cycles

	// Create a set of initial vectors to start the eigensolver.
	// This needs to have the same number of columns as the block size.
	RCP<MV> ivec = rcp (new MV (A->get_num_cols(), blockSize, blockSize));
	ivec->Random ();

	// Create the eigenproblem.  This object holds all the stuff about
	// your problem that Anasazi will see.  In this case, it knows about
	// the matrix A and the inital vectors.
	RCP<Anasazi::BasicEigenproblem<double, MV, OP> > problem =
		rcp (new Anasazi::BasicEigenproblem<double, MV, OP> (A, ivec));

	// Tell the eigenproblem that the operator A is symmetric.
	problem->setHermitian (true);
<commit_msg>[Matrix]: eigensolver runs on 2D sparse matrix directly.<commit_after>// This example computes the eigenvalues of largest magnitude of an
// eigenvalue problem $A x = \lambda x$, using Anasazi's
// implementation of the Block Davidson method.

// Include header for block Davidson eigensolver
#include "AnasaziBlockDavidsonSolMgr.hpp"
// Include header to define eigenproblem Ax = \lambda*x
#include "AnasaziBasicEigenproblem.hpp"
#include "AnasaziOperator.hpp"
#include "FM_MultiVector.h"

#include "safs_file.h"

#include "sparse_matrix.h"

// ****************************************************************************
// BEGIN MAIN ROUTINE
// ****************************************************************************

using namespace fm;

std::atomic<size_t> iter_no;

class FM_Operator//: public Anasazi::Operator<double>
{
	sparse_matrix::ptr mat;
public:
	FM_Operator(sparse_matrix::ptr mat) {
		this->mat = mat;
	}

	virtual void Apply(const FM_MultiVector<double>& x,
			FM_MultiVector<double>& y) const {
		printf("SpMM: y(%s) = A * x(%s)\n", y.get_name().c_str(), x.get_name().c_str());
		block_multi_vector::sparse_matrix_multiply<double>(*mat, *x.get_data(),
				*y.get_data());
		y.sync_fm2ep();

//		assert((size_t) x.GetGlobalLength() == mat->get_num_cols());
//		assert((size_t) y.GetGlobalLength() == mat->get_num_rows());
//		mem_vector::ptr in = mem_vector::create(mat->get_num_cols(),
//				get_scalar_type<double>());
//		mem_vector::ptr out = mem_vector::create(mat->get_num_rows(),
//				get_scalar_type<double>());
//		for (int i = 0; i < x.GetNumberVecs(); i++) {
//			memcpy(in->get_raw_arr(), x.get_ep_mv()[i], in->get_length() * sizeof(double));
//			out->reset_data();
//			mat->multiply<double>(*in, *out);
//			memcpy(y.get_ep_mv()[i], out->get_raw_arr(), out->get_length() * sizeof(double));
//		}
//		y.sync_ep2fm();
	}

	size_t get_num_cols() const {
		return mat->get_num_cols();
	}

	size_t get_num_rows() const {
		return mat->get_num_rows();
	}
};

namespace Anasazi
{

template<>
class OperatorTraits <double, FM_MultiVector<double>, FM_Operator>
{
public:
	/*! \brief This method takes the FM_MultiVector \c x and
	 * applies the FM_Operator \c Op to it resulting in the FM_MultiVector \c y.
	 */
	static void Apply ( const FM_Operator& Op,
			const FM_MultiVector<double>& x, FM_MultiVector<double>& y ) {
		iter_no++;
		Op.Apply(x,y);
	}

};

}

int
main (int argc, char *argv[])
{
	using Teuchos::RCP;
	using Teuchos::rcp;
	using std::cerr;
	using std::cout;
	using std::endl;

	if (argc < 5) {
		fprintf(stderr, "eigensolver conf_file matrix_file index_file nev\n");
		exit(1);
	}

	std::string conf_file = argv[1];
	std::string matrix_file = argv[2];
	std::string index_file = argv[3];
	int nev = atoi(argv[4]); // number of eigenvalues for which to solve

	// Anasazi solvers have the following template parameters:
	//
	//   - Scalar: The type of dot product results.
	//   - MV: The type of (multi)vectors.
	//   - OP: The type of operators (functions from multivector to
	//     multivector).  A matrix (like Epetra_CrsMatrix) is an example
	//     of an operator; an Ifpack preconditioner is another example.
	//
	// Here, Scalar is double, MV is FM_MultiVector, and OP is FM_Operator.
	typedef FM_MultiVector<double> MV;
	typedef FM_Operator OP;
	typedef Anasazi::MultiVecTraits<double, MV> MVT;

	//
	// Set up the test problem.
	//
	config_map::ptr configs = config_map::create(conf_file);
	init_flash_matrix(configs);

	// Load index.
	SpM_2d_index::ptr index;
	safs::safs_file idx_f(safs::get_sys_RAID_conf(), index_file);
	if (idx_f.exist())
		index = SpM_2d_index::safs_load(index_file);
	else
		index = SpM_2d_index::load(index_file);

	// Load matrix.
	sparse_matrix::ptr mat;
	safs::safs_file mat_f(safs::get_sys_RAID_conf(), matrix_file);
	if (mat_f.exist())
		mat = sparse_matrix::create(index, safs::create_io_factory(
					matrix_file, safs::REMOTE_ACCESS));
	else
		mat = sparse_matrix::create(index,
				SpM_2d_storage::load(matrix_file, index));

	RCP<FM_Operator> A = rcp(new FM_Operator(mat));

	// Set eigensolver parameters.
	const double tol = 1.0e-8; // convergence tolerance
	const int blockSize = nev + 1; // block size (number of eigenvectors processed at once)
	const int numBlocks = 8; // restart length
	const int maxRestarts = 100; // maximum number of restart cycles

	// Create a set of initial vectors to start the eigensolver.
	// This needs to have the same number of columns as the block size.
	RCP<MV> ivec = rcp (new MV (A->get_num_cols(), blockSize, blockSize));
	ivec->Random ();

	// Create the eigenproblem.  This object holds all the stuff about
	// your problem that Anasazi will see.  In this case, it knows about
	// the matrix A and the inital vectors.
	RCP<Anasazi::BasicEigenproblem<double, MV, OP> > problem =
		rcp (new Anasazi::BasicEigenproblem<double, MV, OP> (A, ivec));

	// Tell the eigenproblem that the operator A is symmetric.
	problem->setHermitian (true);

{'fraction_non_alphanumeric': 0.16927303465765003, 'fraction_numerical': 0.004120879120879121, 'mean_word_length': 4.368689733408962, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7644675', 'n_tokens_mistral': 3477, 'n_tokens_neox': 3266, 'n_words': 882}