<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_1507030364216_3989">Hello, <br></div><div id="yui_3_16_0_ym19_1_1507030364216_4608"><br></div><div>I am still struggling to load my matrix in a PETSc matrix.<br></div><div id="yui_3_16_0_ym19_1_1507030364216_4282"><br></div><div id="yui_3_16_0_ym19_1_1507030364216_4283">I tried the following code which is part of a c++ function which converts the original matrix to CSR fromat and should load a PETSc matrix.<br></div><div id="yui_3_16_0_ym19_1_1507030364216_3990"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1507030364216_4101">    Mat M;<br id="yui_3_16_0_ym19_1_1507030364216_4098">    MatSetFromOptions(M);<br id="yui_3_16_0_ym19_1_1507030364216_4099">    // fill PETSc matrix<br id="yui_3_16_0_ym19_1_1507030364216_4100">    MatCreateSeqAIJWithArrays(PETSC_COMM_WORLD, n, n, rows, cols, vals, M)</div><div dir="ltr" id="yui_3_16_0_ym19_1_1507030364216_4172"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1507030364216_4173">but I get the following error message when compiling the code:</div><div dir="ltr" id="yui_3_16_0_ym19_1_1507030364216_4174"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1507030364216_4175"> error: cannot convert ‘Mat {aka _p_Mat*}’ to ‘_p_Mat**’ for argument ‘7’ to ‘PetscErrorCode MatCreateSeqAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt*, PetscInt*, PetscScalar*, _p_Mat**)’<br id="yui_3_16_0_ym19_1_1507030364216_4192">     MatCreateSeqAIJWithArrays(PETSC_COMM_WORLD, n, n, rows, cols, vals, M)<br id="yui_3_16_0_ym19_1_1507030364216_4193"><br></div><div id="yui_3_16_0_ym19_1_1507030364216_3988"><span id="yui_3_16_0_ym19_1_1507030364216_4520">What's wrong with this?</span></div><div id="yui_3_16_0_ym19_1_1507030364216_4522"><span id="yui_3_16_0_ym19_1_1507030364216_4520"><br></span></div><div id="yui_3_16_0_ym19_1_1507030364216_4523"><span id="yui_3_16_0_ym19_1_1507030364216_4520">Klaus</span></div> <div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div style="font-family: Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 10px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"><font size="2" face="Arial"> Barry Smith <bsmith@mcs.anl.gov> schrieb am 16:38 Sonntag, 17.September 2017:<br></font></div>  <br><br> <div class="y_msg_container"><div dir="ltr"><br clear="none"> 1)  MatSetValues() has absolutely nothing to do with the format used internally by PETSc to store the matrix. MatSetValues() is used to convey blocks of values into the matrix. <br clear="none"><br clear="none">  2) If you want to load a matrix onto multiple processes from a file NEVER write your own parallel ASCII matrix reader. Instead in either C, C++, Python, or Matlab write a routine that reads in the matrix SEQUENTIALLY and then saves it with MatView() and a binary viewer. You can then load the matrix easily and efficiently in PETSc in parallel with MatLoad<br clear="none"><br clear="none">  3) If you have matrix already in CSR format you can use MatCreateSeqAIJWithArrays()<br clear="none"><br clear="none">  Barry<br clear="none"><br clear="none"><br clear="none"><div class="yqt6835683611" id="yqtfd91006"><br clear="none">> On Sep 17, 2017, at 9:25 AM, Klaus Burkart <<a shape="rect" ymailto="mailto:k_burkart@yahoo.com" href="mailto:k_burkart@yahoo.com">k_burkart@yahoo.com</a>> wrote:<br clear="none">> <br clear="none">> The matrix import function looks like this:<br clear="none">> <br clear="none">> void csr2pet<br clear="none">> (<br clear="none">>     const Foam::lduMatrix & matrix,<br clear="none">>     petsc_declaration<Type> & petsc_matrix  // How to declare the PETsc matrix to be filled?<br clear="none">> )<br clear="none">> {<br clear="none">>     int n = matrix.diag().size(); // small case n = 40800<br clear="none">>     int nnz = matrix.lower().size() + matrix.upper().size() + matrix.diag().size(); // small case nnz = 203800<br clear="none">> <br clear="none">>     // allocate memory for CSR sparse matrix using calloc<br clear="none">>     ScalarType * vals = (ScalarType *)calloc(nnz, sizeof(ScalarType));<br clear="none">>     uint * cols = (uint *)calloc(nnz, sizeof(uint));<br clear="none">>     uint * rows = (uint *)calloc(n, sizeof(uint));<br clear="none">> <br clear="none">>     // call function to convert original LDU matrix to CSR format<br clear="none">>     exPet::ldu2csr(matrix,rows,cols,vals);<br clear="none">> <br clear="none">>     // fill PETsc matrix<br clear="none">>     MatSetValues(petsc_matrix, ?, ?, ?, ?, ?, INSERT_VALUES);<br clear="none">> <br clear="none">>     // free and release the matrix memory<br clear="none">>     free(rows); free(cols); free(vals);  // calloc()<br clear="none">> }<br clear="none">> <br clear="none">> <br clear="none">> Questions:<br clear="none">> <br clear="none">> 1: How to declare the petsc_matrix to be filled by the function with the content of the original matrix?<br clear="none">> <br clear="none">> 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 clear="none">> <br clear="none">>     v         - a logically two-dimensional array of values<br clear="none">>     m, idxm     - the number of rows and their global indices<br clear="none">>     n, idxn     - the number of columns and their global indices<br clear="none">> <br clear="none">> My original matrix is converted to CSR format, i.e. three arrays cols (column_indices), rows (row_start_indices) and vals (values).<br clear="none">> <br clear="none">> How can I load my matrix into a PETsc matrix for parallel processing? MatSetValues(petsc_matrix, ?, ?, ?, ?, ?, INSERT_VALUES);<br clear="none">> <br clear="none">> Klaus<br clear="none"></div></div><br><br></div>  </div> </div>  </div></div></body></html>