<html><head></head><body><div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10px"><div id="yui_3_16_0_ym19_1_1505657988265_7070" dir="ltr">The matrix import function looks like this:<br id="yui_3_16_0_ym19_1_1505657988265_8956"><br id="yui_3_16_0_ym19_1_1505657988265_8957">void csr2pet<br id="yui_3_16_0_ym19_1_1505657988265_8958">(<br id="yui_3_16_0_ym19_1_1505657988265_8959"> const Foam::lduMatrix & matrix,<br id="yui_3_16_0_ym19_1_1505657988265_8960"> petsc_declaration<Type> & petsc_matrix // How to declare the PETsc matrix to be filled?<br id="yui_3_16_0_ym19_1_1505657988265_8961">)<br id="yui_3_16_0_ym19_1_1505657988265_8962">{<br id="yui_3_16_0_ym19_1_1505657988265_8963"> int n = matrix.diag().size(); // small case n = 40800<br id="yui_3_16_0_ym19_1_1505657988265_8964"> int nnz = matrix.lower().size() + matrix.upper().size() + matrix.diag().size(); // small case nnz = 203800<br id="yui_3_16_0_ym19_1_1505657988265_8965"><br id="yui_3_16_0_ym19_1_1505657988265_8966"> // allocate memory for CSR sparse matrix using calloc<br id="yui_3_16_0_ym19_1_1505657988265_8967"> ScalarType * vals = (ScalarType *)calloc(nnz, sizeof(ScalarType));<br id="yui_3_16_0_ym19_1_1505657988265_8968"> uint * cols = (uint *)calloc(nnz, sizeof(uint));<br id="yui_3_16_0_ym19_1_1505657988265_8969"> uint * rows = (uint *)calloc(n, sizeof(uint));<br id="yui_3_16_0_ym19_1_1505657988265_8970"><br id="yui_3_16_0_ym19_1_1505657988265_8971"> // call function to convert original LDU matrix to CSR format<br id="yui_3_16_0_ym19_1_1505657988265_8972"> exPet::ldu2csr(matrix,rows,cols,vals);<br id="yui_3_16_0_ym19_1_1505657988265_8973"><br id="yui_3_16_0_ym19_1_1505657988265_8974"> // fill PETsc matrix<br id="yui_3_16_0_ym19_1_1505657988265_8975"> MatSetValues(petsc_matrix, ?, ?, ?, ?, ?, INSERT_VALUES);<br id="yui_3_16_0_ym19_1_1505657988265_8976"><br id="yui_3_16_0_ym19_1_1505657988265_8977"> // free and release the matrix memory<br id="yui_3_16_0_ym19_1_1505657988265_8978"> free(rows); free(cols); free(vals); // calloc()<br id="yui_3_16_0_ym19_1_1505657988265_8979">}<br id="yui_3_16_0_ym19_1_1505657988265_8980"><br id="yui_3_16_0_ym19_1_1505657988265_8981"><br id="yui_3_16_0_ym19_1_1505657988265_8982">Questions:<br id="yui_3_16_0_ym19_1_1505657988265_8983"><br id="yui_3_16_0_ym19_1_1505657988265_8984">1: How to declare the petsc_matrix to be filled by the function with the content of the original matrix?<br id="yui_3_16_0_ym19_1_1505657988265_8985"><br id="yui_3_16_0_ym19_1_1505657988265_8986">2: MatSetValues(petsc_matrix, ?, ?, ?, ?, ?, INSERT_VALUES); is used to actually fill the petsc_matrix and I was of the opinion that PETsc uses the CSR format but I can't work out how CSR format is described by:<br id="yui_3_16_0_ym19_1_1505657988265_8987"><br id="yui_3_16_0_ym19_1_1505657988265_8988"> v - a logically two-dimensional array of values<br id="yui_3_16_0_ym19_1_1505657988265_8989"> m, idxm - the number of rows and their global indices<br id="yui_3_16_0_ym19_1_1505657988265_8990"> n, idxn - the number of columns and their global indices<br id="yui_3_16_0_ym19_1_1505657988265_8991"><br id="yui_3_16_0_ym19_1_1505657988265_8992">My original matrix is converted to CSR format, i.e. three arrays cols (column_indices), rows (row_start_indices) and vals (values).<br id="yui_3_16_0_ym19_1_1505657988265_8993"><br id="yui_3_16_0_ym19_1_1505657988265_8994">How can I load my matrix into a PETsc matrix for parallel processing? MatSetValues(petsc_matrix, ?, ?, ?, ?, ?, INSERT_VALUES);<br id="yui_3_16_0_ym19_1_1505657988265_8995"><br id="yui_3_16_0_ym19_1_1505657988265_8996">Klaus<br></div></div></body></html>