AMGX icon indicating copy to clipboard operation
AMGX copied to clipboard

Example partition vector file

Open gantech opened this issue 10 months ago • 1 comments

Hello.. could I please get an example partition vector file for the distributed example https://github.com/NVIDIA/AMGX/blob/main/examples/amgx_mpi_capi.c

gantech avatar Feb 19 '25 16:02 gantech

@gantech in the mentioned example file AMGX_read_system_distributed API is used that accepts partition vector from the memory. You can generate it in your application or, like it's done in the example, read it from the binary file. Here is small snippet that shows how this vector look like and how it can be written to file later to be used by mentioned example:

#include <iostream>
#include <vector>
#include <fstream>
#include <cstdint>

{
    // assume sample 12x12 matrix https://github.com/NVIDIA/AMGX/blob/main/examples/matrix.mtx
    // vector of 32-bit integers with the size of the "number of rows in the matrix", where each integer represents process id that should own respective row
    // this partition vector is for 3 processes, first 4 rows will belong to GPU 0, second 4 rows - to GPU 1, and last 4 rows - to GPU 2
    std::vector<int> partition_data = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2};

    std::ofstream parition_file("partvec.bin", std::ios::binary);

    parition_file.write(reinterpret_cast<const char*>(data.data()), data.size() * sizeof(int32));
}

Note, that in the case you don't specify partition vector in the example (or pass nullptr to the API) - library will just split number of rows equally between processes, which should be the same as the snippet above.

this snippet aligns with what another AMGX example does: https://github.com/NVIDIA/AMGX/blob/main/examples/amgx_mpi_capi_agg.c#L384-L385

marsaev avatar Feb 19 '25 21:02 marsaev