<commit_before>#include "SparseMatrix.h"
#include <string.h>
#include <iostream>

using namespace std;

SparseMatrix::SparseMatrix() {
	// TODO Auto-generated constructor stub
	m_rowStartsMarked = false;
}

SparseMatrix::~SparseMatrix() {
	// TODO Auto-generated destructor stub
}

void SparseMatrix::printSummary() {
	cout << "Matrix summary" << endl;
	cout << "name = " << m_name << endl;
	cout << "#rows = " << m_rows << endl;
	cout << "#cols = " << m_cols << endl;
	cout << "#nz = " << m_nz << endl;
}

bool SparseMatrix::isSquare() {
	return m_cols == m_rows;
}

SparseMatrix* SparseMatrix::fromMemory(unsigned int metaDataBase) {
	CompressedSparseMetadata * metadata = (CompressedSparseMetadata *) metaDataBase;

	if(metadata->numCols == 0 || metadata->numRows == 0 || metadata->numNZ == 0) {
		cerr << "Error: matrix data at " << hex << metaDataBase << dec << " is invalid" << endl;
		return 0;
	}

	SparseMatrix * ret = new SparseMatrix();
	ret->m_cols = metadata->numCols;
	ret->m_rows = metadata->numRows;
	ret->m_nz = metadata->numNZ;
	ret->m_indPtrs = (SpMVIndex*) (metadata->indPtrBase);
	ret->m_inds = (SpMVIndex*) (metadata->indBase);
	ret->m_nzData = (SpMVData*) (metadata->nzDataBase);
	ret->m_rowStartsMarked = false;

	return ret;
}

void SparseMatrix::markRowStarts() {
	if(!m_rowStartsMarked) {
		m_rowStartsMarked = true;
		// flags to mark encountered row indices
		char * encounteredRow = new char[m_rows];
		// set all encountered flags to zero
		memset(encounteredRow, 0, m_rows);

		for(SpMVIndex nz = 0; nz < m_nz; nz++) {
			SpMVIndex rowInd = m_inds[nz];
			if(!encounteredRow[rowInd]) {
				// set as encountered + add cold miss bit at highest position
				encounteredRow[rowInd] = 1;
				m_inds[nz] = rowInd | (1 << 31);
			}
		}

		delete [] encounteredRow;
	}
}<commit_msg>use bitmaps for markRowStarts<commit_after>#include "SparseMatrix.h"
#include <string.h>
#include <iostream>
#include <vector>

using namespace std;

SparseMatrix::SparseMatrix() {
	// TODO Auto-generated constructor stub
	m_rowStartsMarked = false;
}

SparseMatrix::~SparseMatrix() {
	// TODO Auto-generated destructor stub
}

void SparseMatrix::printSummary() {
	cout << "Matrix summary" << endl;
	cout << "name = " << m_name << endl;
	cout << "#rows = " << m_rows << endl;
	cout << "#cols = " << m_cols << endl;
	cout << "#nz = " << m_nz << endl;
}

bool SparseMatrix::isSquare() {
	return m_cols == m_rows;
}

SparseMatrix* SparseMatrix::fromMemory(unsigned int metaDataBase) {
	CompressedSparseMetadata * metadata = (CompressedSparseMetadata *) metaDataBase;

	if(metadata->numCols == 0 || metadata->numRows == 0 || metadata->numNZ == 0) {
		cerr << "Error: matrix data at " << hex << metaDataBase << dec << " is invalid" << endl;
		return 0;
	}

	SparseMatrix * ret = new SparseMatrix();
	ret->m_cols = metadata->numCols;
	ret->m_rows = metadata->numRows;
	ret->m_nz = metadata->numNZ;
	ret->m_indPtrs = (SpMVIndex*) (metadata->indPtrBase);
	ret->m_inds = (SpMVIndex*) (metadata->indBase);
	ret->m_nzData = (SpMVData*) (metadata->nzDataBase);
	ret->m_rowStartsMarked = false;

	return ret;
}

void SparseMatrix::markRowStarts() {
	if(!m_rowStartsMarked) {
		m_rowStartsMarked = true;
		// flags to mark encountered row indices
		// packed as 32-bit fields for smaller memory/cache footprint
		unsigned int encSize = (m_rows/32)+1;
		unsigned int * encounteredRow = new unsigned int[encSize];

		// set all encountered flags to zero
		memset(encounteredRow, 0, sizeof(unsigned int)*encSize);

		for(SpMVIndex nz = 0; nz < m_nz; nz++) {
			SpMVIndex rowInd = m_inds[nz];
			unsigned int bitInd = rowInd / 32;
			unsigned int bitMod = rowInd % 32;
			unsigned int bVal = encounteredRow[bitInd];
			if((bVal & (1 << bitMod)) == 0) {
				// set as encountered + add cold miss bit at highest position
				encounteredRow[bitInd] = bVal | (1 << bitMod);
				m_inds[nz] = rowInd | (1 << 31);
			}
		}

		delete [] encounteredRow;
	}
}
{'fraction_non_alphanumeric': 0.1521076688674454, 'fraction_numerical': 0.00787201625190452, 'mean_word_length': 4.224137931034483, 'pattern_counts': {'":': 0, '<': 98, '<?xml version=': 0, '>': 40, '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': '6507591', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1392, 'n_words': 339}