AMGX icon indicating copy to clipboard operation
AMGX copied to clipboard

AMGX_solver_solve_with_0_initial_guess() requires explicit initializing of solution vector

Open vmasyagin opened this issue 5 years ago • 5 comments

{ AMGX_matrix_handle A1; AMGX_vector_handle rhs; AMGX_vector_handle sln;

        AMGX_matrix_create(&A1, rsrc, AMGX_mode_dDDI);
        AMGX_vector_create(&rhs, rsrc, AMGX_mode_dDDI);
        AMGX_vector_create(&sln, rsrc, AMGX_mode_dDDI);

        double data[] = {1, -2, -3, 1, 1, -4, -5, 1};
        AMGX_pin_memory(data, sizeof(double) * 8);
        int col_ind[] = {0, 1};
        int row_ptr[] = {0, 1, 2};
        AMGX_matrix_upload_all(A1, 2, 2, 2, 2, row_ptr, col_ind, data, 0);
        int nn, block_dimx, block_dimy;
        AMGX_matrix_get_size(A1, &nn, &block_dimx, &block_dimy);
        double data1[] = {1, 2, 3, 4};
        AMGX_pin_memory(data1, sizeof(double) * 4);
        AMGX_vector_upload(rhs, 2, 2, data1);
        int nnn, block_dim;
        AMGX_vector_get_size(rhs, &nnn, &block_dim);
        //AMGX_vector_create(x1, )
        AMGX_solver_create(&solver, rsrc, AMGX_mode_dDDI, config);
        AMGX_solver_setup(solver, A1);
        AMGX_solver_solve_with_0_initial_guess(solver, rhs, sln);
    }

Good afternoon. Please tell me why in this example I get an error of mismatch of dimensions? Purely in blocks everything turns out correctly. I use the solver FGMRES. Maybe there is a working example in which the matrix and vector are initialized from arrays, and not from a file. The documentation seems to be doing everything right.

vmasyagin avatar Feb 06 '20 11:02 vmasyagin

Hey @vmasyagin, You can try looking into following examples:

  1. https://github.com/NVIDIA/AMGX/blob/master/examples/amgx_mpi_poisson5pt.c 5pt stencil, data generated in the host buffers
  2. https://github.com/NVIDIA/AMGX/blob/master/examples/amgx_mpi_capi_agg.c data read from file to the host buffers where you can inspect them and see what data is passed to API Those are multi-gpu examples, but with 1 rank it's equivalent to the single-GPU run.

Regarding your example - what exact config do you use? (how do you create rsrc). What API call throws an error?

marsaev avatar Feb 10 '20 18:02 marsaev

My quick guess would be that AMGX doesn't know dimensions of sln vector, since you created but it was not initialized, i will check if we set solution dimensions/block size in case of calling AMGX_solver_solve_with_0_initial_guess(). Can you also try calling AMGX_vector_upload(sln, 2, 2, data1); to see if it will help?

Thanks,

marsaev avatar Feb 10 '20 19:02 marsaev

My quick guess would be that AMGX doesn't know dimensions of sln vector, since you created but it was not initialized, i will check if we set solution dimensions/block size in case of calling AMGX_solver_solve_with_0_initial_guess(). Can you also try calling AMGX_vector_upload(sln, 2, 2, data1); to see if it will help?

Thanks,

Thanks a lot for the help, the problem was really that. Also thanks for the links with examples, this is what I needed.

vmasyagin avatar Feb 12 '20 17:02 vmasyagin

No problem. I should note that you are using AMGX_solver_solve_with_0_initial_guess() and it would be logical for AMGX to not expect user to set or initialize initial guess manually (since it's assumed to be zero). This is not happening right now - what i suggested is a workaround - it induces additional explicit memory. I think it would be nice if AMGX handled this case and set correct sizes for initial guess in AMGX_solver_solve_with_0_initial_guess() call. If you don't mind i will convert this issue to the corresponding change tracking.

marsaev avatar Feb 13 '20 18:02 marsaev

Tracking internally: AMGX-53

marsaev avatar Apr 07 '21 19:04 marsaev