MCPcopy Create free account
hub / github.com/AMReX-Codes/amrex / Initialize_without_split

Function Initialize_without_split

Src/Base/AMReX_MPMD.cpp:44–95  ·  view source on GitHub ↗

Initialize_without_split function assigns and checks the required AMReX_MPMD variables. This function is internally leveraged by Initialize function. This function needs to be used EXPLICITLY ONLY with pyAMReX (python) so that the communication split can be performed using a python library, for example, mpi4py. */

Source from the content-addressed store, hash-verified

42library, for example, mpi4py.
43*/
44void Initialize_without_split (int argc, char* argv[])
45{
46 initialized = true;
47 int flag;
48 MPI_Initialized(&flag);
49 if (!flag) {
50 MPI_Init(&argc, &argv);
51 mpi_initialized_by_us = true;
52 }
53
54 MPI_Comm_rank(MPI_COMM_WORLD, &myproc);
55 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
56
57 int* p = nullptr;
58 MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_APPNUM, &p, &flag);
59 appnum = (flag && p) ? *p : -1;
60
61 std::vector<int> all_appnum(nprocs);
62 MPI_Allgather(&appnum, 1, MPI_INT, all_appnum.data(), 1, MPI_INT, MPI_COMM_WORLD);
63 int napps = num_unique_elements(all_appnum);
64
65 // MPI_APPNUM does not appear to work with slurm on some systems.
66 if (napps != 2) {
67 std::vector<int> all_argc(nprocs);
68 MPI_Allgather(&argc, 1, MPI_INT, all_argc.data(), 1, MPI_INT, MPI_COMM_WORLD);
69 napps = num_unique_elements(all_argc);
70 if (napps == 2) {
71 appnum = static_cast<int>(argc != all_argc[0]);
72 }
73 }
74
75 if (napps != 2) {
76 std::string exename;
77 if (argc > 0) {
78 exename = std::string(argv[0]);
79 }
80 unsigned long long hexe = std::hash<std::string>{}(exename);
81 std::vector<unsigned long long> all_hexe(nprocs);
82 MPI_Allgather(&hexe, 1, MPI_UNSIGNED_LONG_LONG,
83 all_hexe.data(), 1, MPI_UNSIGNED_LONG_LONG, MPI_COMM_WORLD);
84 napps = num_unique_elements(all_hexe);
85 if (napps == 2) {
86 appnum = static_cast<int>(hexe != all_hexe[0]);
87 }
88 }
89
90 if (napps != 2) {
91 std::cout << "amrex::MPMD only supports two programs." << '\n';
92 MPI_Abort(MPI_COMM_WORLD, 1);
93 }
94
95}
96
97MPI_Comm Initialize (int argc, char* argv[])
98{

Callers 1

InitializeFunction · 0.85

Calls 2

num_unique_elementsFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected