char MemoryInstrumenter::addType(const std::string & label, bool cumul, HookFunction hook, void * param) { HMAT_ASSERT_MSG(output_ == NULL, "Cannot call addType after setFile"); HMAT_ASSERT_MSG(write_sampling == 1 || !cumul, "Cannot use write sub sampling with cumulative records."); cumulatives_.push_back(cumul); labels_.push_back(label); hooks_.push_back(hook); hookParams_.push_back(param); return labels_.size() - 1; }
void MemoryInstrumenter::setFile(const std::string & filename) { #ifdef HMAT_MEM_INSTR filename_ = filename; output_ = fopen(filename.c_str(), "w+"); HMAT_ASSERT_MSG(output_ != NULL, "Cannot open %s", filename.c_str()); start_ = now(); fullMatrixMem_ = 0; mallinfo_counter = 0; FILE * labelsf = fopen((filename_+".labels").c_str(), "w"); for(int i = 0; i < labels_.size(); i++) { fputs(labels_[i].c_str(), labelsf); fputc('\n', labelsf); } fclose(labelsf); enabled_ = true; #else ignore_unused_arg(filename); #endif }
template<typename T> int truncatedSdd(ScalarArray<T>* m, ScalarArray<T>** u, Vector<double>** sigma, ScalarArray<T>** vt) { DECLARE_CONTEXT; // Allocate free space for U, S, V int rows = m->rows; int cols = m->cols; int p = min(rows, cols); *u = new ScalarArray<T>(rows, p); *sigma = new Vector<double>(p); *vt = new ScalarArray<T>(p, cols); assert(m->lda >= m->rows); char jobz = 'S'; int mm = rows; int n = cols; T* a = m->m; int lda = rows; int info; { const size_t _m = mm, _n = n; // Warning: These quantities are a rough approximation. // What's wrong with these estimates: // - Golub only gives 14 * M*N*N + 8 N*N*N // - This is for real numbers // - We assume the same number of * and + size_t adds = 7 * _m * _n * _n + 4 * _n * _n * _n; size_t muls = 7 * _m * _n * _n + 4 * _n * _n * _n; increment_flops(Multipliers<T>::add * adds + Multipliers<T>::mul * muls); } info = sddCall<T>(jobz, mm, n, a, lda, (*sigma)->m, (*u)->m, (*u)->lda, (*vt)->m, (*vt)->lda); HMAT_ASSERT_MSG(!info, "Error in ?gesdd, info=%d", info); return info; }