void CSRMatrix::add_from_coo(CooMatrix *m) { free_data(); this->size = m->get_size(); this->nnz = m->get_nnz(); this->complex = m->is_complex(); // allocate data this->Ap = new int[this->size + 1]; this->Ai = new int[this->nnz]; if (is_complex()) this->Ax_cplx = new cplx[this->nnz]; else this->Ax = new double[this->nnz]; // get data int *row = new int[this->nnz]; int *col = new int[this->nnz]; if (is_complex()) { cplx *data = new cplx[this->nnz]; m->get_row_col_data(row, col, data); coo_to_csr(this->size, this->nnz, row, col, data, Ap, Ai, Ax_cplx); if (data != NULL) delete[] data; } else { double *data = new double[this->nnz]; m->get_row_col_data(row, col, data); coo_to_csr(this->size, this->nnz, row, col, data, Ap, Ai, Ax); if (data != NULL) delete[] data; } // free data if (row != NULL) delete[] row; if (col != NULL) delete[] col; }
void coo_to_csc(int size, int nnz, int *row, int *col, T *A, int *Ap, int *Ai, T *Ax) { coo_to_csr(size, nnz, col, row, A, Ap, Ai, Ax); }
int main(int argc, char *argv[]) { int nrep = 1, BS = 0; //parseArgs(argc,argv); double cusp_time; int ok = -1; double init_time = omp_get_wtime(); //init_load(argc,argv, &_numRows, &_numCols, &_numValues, _numericalValues, _rowOffsets,_colIndexValues, _vector, _output_vector,&check_res,&just_analyse); if (argc < 2) { exit(EXIT_FAILURE); } char const *mmfile = argv[1]; printf("Matrix File %s\n", mmfile); int m, n, nz; int *i_idx, *j_idx; double *a; check_res = 1; just_analyse = 0; if (argc == 3) if (argv[2][0] == 'a') { printf("Analyzing matrix...\n"); just_analyse = 1; } else check_res = 0; //read_mm_matrix (mmfile, &m, &n, &nz, &i_idx, &j_idx, &a); //enum sparse_matrix_file_format_t informat; struct sparse_matrix_t *A = load_sparse_matrix(MATRIX_MARKET, argv[1]); if (valid_sparse_matrix(A)) printf("\n### Sparse matrix is valid ###\n\n"); else printf("\n### Invalid sparse matrix! ###\n\n"); struct csr_matrix_t *B = NULL; B = coo_to_csr(A->repr); init_time = omp_get_wtime() - init_time; _numericalValues = (double *) B->values; if (just_analyse) { check_matrix(B->m, B->n, B->nnz, _numericalValues, B->colidx, B->rowptr); return 0; } _vector = malloc(sizeof(double) * B->m); _output_vector = malloc(sizeof(double) * B->m); for (int i = 0; i < B->m; ++i) _vector[i] = i; double ss_time; _numRows = (uint) B->m; _numValues = (uint) B->nnz; _rowOffsets = (uint) B->rowptr; _colIndexValues = (uint) B->colidx; int tmp; double db_time = omp_get_wtime(); #pragma omp target device(acc) #pragma omp task inout([_numValues]_numericalValues, [_numValues]_colIndexValues, [_numRows]_rowOffsets, [_numRows]_vector , [_numRows]_output_vector ) #pragma omp teams num_teams(1) thread_limit(1) { } #pragma omp taskwait noflush db_time = omp_get_wtime() - db_time; ss_time = omp_get_wtime(); SpMV_CSR(_numRows, _numValues, _numericalValues, _colIndexValues, _rowOffsets, _vector, _output_vector); #pragma omp taskwait noflush ss_time = omp_get_wtime() - ss_time; #pragma omp taskwait FILE *fp; fp = fopen("result.txt", "w+"); for (int i = 0; i < B->m; ++i) fprintf(fp, "%.2lf\n", _output_vector[i]); fclose(fp); // if(check_res!=0) // { // ok = check_result(_output_vector,_vector); // cusp_time = get_cusp_time(); // } unsigned long nops = (unsigned long) 2 * (B->m + B->nnz); prtspeed(_numRows, BS, ss_time, init_time, db_time, 0, 0, ok, nops); return 0; }