Hello,

I am currently experiencing some difficulties when I try to parallelize a
program using the DMNetwork object. The code works perfectly on one
processor but fails whenever I have more than 1 which has to do either with
the way I distribute the graph on the parallel structure and or the way my
equations are written for Jacobian and Residual (or both)...well it seems
that I am not distributing properly my graph anyway in parallel...Below I
share the portion of the code that seems suspicious to me :
PetscMPIInt rank;
  PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
  // PetscCall(DMNetworkCreate(PETSC_COMM_SELF, &dmNetwork));
  PetscCall(DMNetworkCreate(PETSC_COMM_WORLD, &dmNetwork));


  PetscInt nodeComponentId, edgeComponentId;
  PetscCall(DMNetworkRegisterComponent(dmNetwork, "NodeComp", sizeof(
NodeData),
                                       &nodeComponentId));
  PetscCall(DMNetworkRegisterComponent(dmNetwork, "EdgeComp", sizeof(
EdgeData),
                                       &edgeComponentId));


  // PetscCall(DMNetworkSetNumSubNetworks(dmNetwork, 1, 1));
  PetscCall(DMNetworkSetNumSubNetworks(dmNetwork, PETSC_DECIDE, 1));

  PetscInt num_edges = (rank == 0) ? ctx->TotalEdges : 0;
  PetscInt *edges_ptr = (rank == 0) ? ctx->EdgeConnectivity.data() : NULL;
  // PetscInt netNum;

  PetscCall(DMNetworkAddSubnetwork(dmNetwork, "CircuitPrimaire", num_edges,
                                   edges_ptr, NULL));

  // 3. Construction de la topologie
  PetscCall(DMNetworkLayoutSetUp(dmNetwork));

  if(rank == 0){

    PetscInt vStart, vEnd, eStart, eEnd;
    PetscCall(DMNetworkGetVertexRange(dmNetwork, &vStart, &vEnd));
    PetscCall(DMNetworkGetEdgeRange(dmNetwork, &eStart, &eEnd));


    for (PetscInt v = vStart; v < vEnd; v++) {
      PetscCall(DMNetworkAddComponent(dmNetwork, v, nodeComponentId,
                                      &ctx->nodes[v - vStart], ctx
->NumberOfIsotopes));
    }

    // Attribution des arêtes (Edges)
    for (PetscInt e = eStart; e < eEnd; e++) {

       PetscInt local_e_idx = e - eStart;

      // ANCRAGE DE L'ORIENTATION : On va chercher la source et la
destination globales d'origine
      // stockées linéairement dans votre tableau d'arêtes XML : [2*e] et
[2*e + 1]
      ctx->edges[local_e_idx].source_xml      = ctx->EdgeConnectivity[2 *
local_e_idx];
      ctx->edges[local_e_idx].destination_xml = ctx->EdgeConnectivity[2 *
local_e_idx + 1];

      PetscCall(
          DMNetworkAddComponent(dmNetwork, e, edgeComponentId, &ctx->edges[
local_e_idx], 0));
    }

    // PetscCall(DMNetworkSetVertexLocalToGlobalOrdering)
  }


  PetscCall(DMSetUp(dmNetwork));
  PetscCall(DMNetworkDistribute(&dmNetwork, 0));


OS Version : Ubuntu22.04.01
Compiler : g++ 11.4.0
Petsc Version : 3.24.3
Petsc Object : DMNetwork

Do you see anything wrong with this snippet ?
Kind regards,
Christophe Chalons

Reply via email to