Skip to content

Commit 6bcc013

Browse files
committed
#2472: runtime: remove error-prone argv container--directly build ArgConfig during preconfigure
1 parent 482ecf6 commit 6bcc013

File tree

7 files changed

+193
-177
lines changed

7 files changed

+193
-177
lines changed

src/vt/collective/collective_ops.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "vt/runtime/runtime.h"
4747
#include "vt/scheduler/scheduler.h"
4848
#include "vt/runtime/runtime_inst.h"
49+
#include "vt/configs/arguments/args.h"
4950

5051
#include <memory>
5152
#include <cstdlib>
@@ -246,6 +247,31 @@ RuntimePtrType CollectiveAnyOps<instance>::initialize(
246247
return runtime::makeRuntimePtr(rt_ptr);
247248
}
248249

250+
template <runtime::RuntimeInstType instance>
251+
/*static*/ RuntimePtrType CollectiveAnyOps<instance>::initializePreconfigured(
252+
std::unique_ptr<arguments::ArgConfig> arg_config, MPI_Comm* comm
253+
) {
254+
using vt::runtime::RuntimeInst;
255+
using vt::runtime::Runtime;
256+
using vt::runtime::eRuntimeInstance;
257+
258+
MPI_Comm resolved_comm = comm not_eq nullptr ? *comm : MPI_COMM_WORLD;
259+
260+
RuntimeInst<instance>::rt = std::make_unique<Runtime>(
261+
std::move(arg_config), resolved_comm, eRuntimeInstance::DefaultInstance
262+
);
263+
264+
auto rt_ptr = RuntimeInst<instance>::rt.get();
265+
if (instance == runtime::RuntimeInstType::DefaultInstance) {
266+
// Set global variable for default instance for backward compatibility
267+
::vt::rt = rt_ptr;
268+
curRT = rt_ptr;
269+
}
270+
RuntimeInst<instance>::rt->initialize();
271+
272+
return runtime::makeRuntimePtr(rt_ptr);
273+
}
274+
249275
template <runtime::RuntimeInstType instance>
250276
void CollectiveAnyOps<instance>::setCurrentRuntimeTLS(RuntimeUnsafePtrType in) {
251277
bool const has_rt = in != nullptr;

src/vt/collective/collective_ops.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ struct CollectiveAnyOps {
7272
{
7373
return initialize(argc, argv, is_interop, comm, appConfig);
7474
}
75+
76+
/**
77+
* \brief Initialize a VT runtime with arguments preconfigured
78+
*
79+
* \param[in] arg_config the preconfigured arguments
80+
* \param[in] comm the communicator for VT to use
81+
*
82+
* \return the runtime pointer
83+
*/
84+
static RuntimePtrType initializePreconfigured(
85+
std::unique_ptr<arguments::ArgConfig> arg_config,
86+
MPI_Comm* comm = nullptr
87+
);
88+
7589
static void finalize(RuntimePtrType in_rt = nullptr);
7690
static void scheduleThenFinalize(RuntimePtrType in_rt = nullptr);
7791
static void setCurrentRuntimeTLS(RuntimeUnsafePtrType in_rt = nullptr);

src/vt/collective/startup.cc

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,25 @@
4646
#include "vt/collective/collective_ops.h"
4747
#include "vt/runtime/runtime_headers.h"
4848
#include "vt/context/context.h"
49+
#include "vt/configs/arguments/args.h"
4950

5051
namespace vt {
5152

52-
std::unique_ptr<arguments::ArgvContainer>
53-
preconfigure(int& argc, char**& argv) {
54-
return std::make_unique<arguments::ArgvContainer>(argc, argv);
53+
std::unique_ptr<arguments::ArgConfig> preconfigure(
54+
int& argc, char**& argv, MPI_Comm comm, arguments::AppConfig const* app_config
55+
) {
56+
auto arg_config = std::make_unique<arguments::ArgConfig>();
57+
runtime::Runtime::startupMPIConfigArgs(
58+
argc, argv, true, comm, arg_config.get(), app_config
59+
);
60+
return arg_config;
5561
}
5662

5763
RuntimePtrType initializePreconfigured(
58-
MPI_Comm* comm, arguments::AppConfig const* appConfig,
59-
arguments::ArgvContainer const* preconfigure_args
64+
std::unique_ptr<arguments::ArgConfig> arg_config,
65+
MPI_Comm* comm
6066
) {
61-
arguments::ArgvContainer args =
62-
preconfigure_args ? *preconfigure_args : arguments::ArgvContainer{};
63-
64-
auto argc = args.getArgc();
65-
auto argv_container = args.getArgvDeepCopy();
66-
auto argv = argv_container.get();
67-
bool const is_interop = comm != nullptr;
68-
auto ptr = CollectiveOps::initialize(
69-
argc, argv, is_interop, comm, appConfig
70-
);
71-
for (int i = 0; i < argc; i++) {
72-
free(argv_container[i]);
73-
};
74-
return ptr;
67+
return CollectiveOps::initializePreconfigured(std::move(arg_config), comm);
7568
}
7669

7770
// vt::{initialize,finalize} for main ::vt namespace

src/vt/collective/startup.h

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,58 @@
4646

4747
#include "vt/config.h"
4848
#include "vt/runtime/runtime_headers.h"
49-
#include "vt/configs/arguments/argv_container.h"
5049
#include <mpi.h>
5150

5251
namespace vt {
5352

54-
std::unique_ptr<arguments::ArgvContainer>
55-
preconfigure(int& argc, char**& argv);
53+
/**
54+
* \brief Preconfigure VT with argc/argv. This will remove all VT arguments and
55+
* create a configuration for VT that should be passed to
56+
* \c initializePreconfigured. Optionally, one many specify an MPI communicator
57+
* to use (otherwise, it defaults to \c MPI_COMM_WORLD). Additionally, a
58+
* custom app configuration may be passed to directly configure VT.
59+
*
60+
* \note MPI must be initialized to call this function because if an error
61+
* occurs it uses MPI rank to limit how many times the error text gets printed.
62+
*
63+
* \param[in] argc argc (modifies it to remove VT arguments)
64+
* \param[in] argv argv (modifies it to remove VT arguments)
65+
* \param[in] comm (optional) MPI communicator to use
66+
* \param[in] app_config (optional) base VT configuration to use
67+
*
68+
* \return the \c arguments::ArgConfig to pass to VT
69+
*/
70+
std::unique_ptr<arguments::ArgConfig> preconfigure(
71+
int& argc, char**& argv, MPI_Comm comm = MPI_COMM_WORLD,
72+
arguments::AppConfig const* app_config = nullptr
73+
);
74+
75+
/**
76+
* \brief Initialize VT after it has been preconfigured
77+
*
78+
* \param[in] arg_config the arg config
79+
* \param[in] comm optional communicator
80+
*
81+
* \return the runtime pointer
82+
*/
5683
RuntimePtrType initializePreconfigured(
57-
MPI_Comm* comm = nullptr,
58-
arguments::AppConfig const* appConfig = nullptr,
59-
arguments::ArgvContainer const* preconfigure_args = nullptr);
84+
std::unique_ptr<arguments::ArgConfig> arg_config,
85+
MPI_Comm* comm = nullptr
86+
);
6087

6188
RuntimePtrType initialize(
6289
int& argc, char**& argv, MPI_Comm* comm = nullptr,
6390
arguments::AppConfig const* appConfig = nullptr
6491
);
92+
6593
RuntimePtrType initialize(MPI_Comm* comm = nullptr);
94+
6695
RuntimePtrType initialize(
6796
int& argc, char**& argv, arguments::AppConfig const* appConfig
6897
);
6998

7099
void finalize(RuntimePtrType in_rt);
100+
71101
void finalize();
72102

73103
} /* end namespace vt */

src/vt/configs/arguments/argv_container.h

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)