@@ -545,8 +545,9 @@ CellElementReturn WriteElements(const CGNS &cgns, apf::Mesh *m, apf::GlobalNumbe
545545        cgp_error_exit ();
546546
547547      std::vector<int > allNumbersForThisType (m->getPCU ()->Peers (), 0 );
548-       MPI_Allgather (&numbersByElementType[o], 1 , MPI_INT, allNumbersForThisType.data (), 1 ,
549-                     MPI_INT, m->getPCU ()->GetMPIComm ());
548+       m->getPCU ()->Allgather (
549+         &numbersByElementType[o], allNumbersForThisType.data (), 1 
550+       );
550551
551552      cgsize_t  num = 0 ;
552553      for  (int  i = 0 ; i < m->getPCU ()->Self (); i++)
@@ -656,8 +657,7 @@ void AddBocosToMainBase(const CGNS &cgns, const CellElementReturn &cellResults,
656657        }
657658
658659        std::vector<int > allNumbersForThisType (m->getPCU ()->Peers (), 0 );
659-         MPI_Allgather (&number, 1 , MPI_INT, allNumbersForThisType.data (), 1 ,
660-                       MPI_INT, m->getPCU ()->GetMPIComm ());
660+         m->getPCU ()->Allgather (&number, allNumbersForThisType.data (), 1 );
661661
662662        cgsize_t  num = 0 ;
663663        for  (int  i = 0 ; i < m->getPCU ()->Self (); i++)
@@ -684,19 +684,16 @@ void AddBocosToMainBase(const CGNS &cgns, const CellElementReturn &cellResults,
684684      }
685685    }
686686    std::vector<int > cacheStarts (m->getPCU ()->Peers (), 0 );
687-     MPI_Allgather (&cacheStart, 1 , MPI_INT, cacheStarts.data (), 1 ,
688-                   MPI_INT, m->getPCU ()->GetMPIComm ());
687+     m->getPCU ()->Allgather (&cacheStart, cacheStarts.data (), 1 );
689688    std::vector<int > cacheEnds (m->getPCU ()->Peers (), 0 );
690-     MPI_Allgather (&cacheEnd, 1 , MPI_INT, cacheEnds.data (), 1 ,
691-                   MPI_INT, m->getPCU ()->GetMPIComm ());
689+     m->getPCU ()->Allgather (&cacheEnd, cacheEnds.data (), 1 );
692690    return  std::make_pair (cacheStarts, cacheEnds);
693691  };
694692
695693  const  auto  globalElementList = [&m](const  std::vector<cgsize_t > &bcList, std::vector<cgsize_t > &allElements) {
696694    std::vector<int > sizes (m->getPCU ()->Peers (), 0 ); //  important initialiser
697695    const  int  l = bcList.size ();
698-     MPI_Allgather (&l, 1 , MPI_INT, sizes.data (), 1 ,
699-                   MPI_INT, m->getPCU ()->GetMPIComm ());
696+     m->getPCU ()->Allgather (&l, sizes.data (), 1 );
700697
701698    int  totalLength = 0 ;
702699    for  (const  auto  &i : sizes)
@@ -708,9 +705,15 @@ void AddBocosToMainBase(const CGNS &cgns, const CellElementReturn &cellResults,
708705      displacement[i] = displacement[i - 1 ] + sizes[i - 1 ];
709706
710707    allElements.resize (totalLength);
708+     #ifndef  SCOREC_NO_MPI
709+     PCU_Comm comm;
710+     m->getPCU ()->DupComm (&comm);
711711    MPI_Allgatherv (bcList.data (), bcList.size (), MPI_INT, allElements.data (),
712-                    sizes.data (), displacement.data (), MPI_INT,
713-                    m->getPCU ()->GetMPIComm ());
712+                    sizes.data (), displacement.data (), MPI_INT, comm);
713+     MPI_Comm_free (&comm);
714+     #else 
715+     std::copy (bcList.begin (), bcList.end (), allElements.begin ());
716+     #endif 
714717  };
715718
716719  const  auto  doVertexBC = [&](const  auto  &iter) {
@@ -1046,7 +1049,8 @@ void WriteCGNS(const char *prefix, apf::Mesh *m, const apf::CGNSBCMap &cgnsBCMap
10461049  sizes[2 ] = 0 ;                 //  nodes are unsorted, as defined by api
10471050
10481051  //  Copy communicator
1049-   auto  communicator = m->getPCU ()->GetMPIComm ();
1052+   PCU_Comm communicator;
1053+   m->getPCU ()->DupComm (&communicator);
10501054  cgp_mpi_comm (communicator);
10511055  // 
10521056  cgp_pio_mode (CGP_INDEPENDENT);
@@ -1134,6 +1138,9 @@ void WriteCGNS(const char *prefix, apf::Mesh *m, const apf::CGNSBCMap &cgnsBCMap
11341138  destroyGlobalNumbering (gcn);
11351139  // 
11361140  cgp_close (cgns.index );
1141+   #ifndef  SCOREC_NO_MPI
1142+   MPI_Comm_free (&communicator);
1143+   #endif 
11371144}
11381145} //  namespace
11391146
0 commit comments