1
1
openmpi/src/mpi/runtime/ompi_mpi_init.c

399 строки
12 KiB
C
Исходник Обычный вид История

/*
* Copyright (c) 2004-2005 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
* All rights reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "include/constants.h"
#include "mpi/runtime/mpiruntime.h"
#include "mpi/runtime/params.h"
#include "runtime/runtime.h"
#include "runtime/ompi_progress.h"
#include "util/sys_info.h"
#include "util/proc_info.h"
2004-09-10 07:21:03 +04:00
#include "util/session_dir.h"
#include "mpi.h"
#include "communicator/communicator.h"
#include "group/group.h"
#include "info/info.h"
#include "util/show_help.h"
#include "util/stacktrace.h"
#include "errhandler/errcode.h"
#include "errhandler/errclass.h"
#include "request/request.h"
#include "op/op.h"
#include "file/file.h"
#include "attribute/attribute.h"
#include "threads/thread.h"
#include "mca/base/base.h"
#include "mca/allocator/base/base.h"
#include "mca/allocator/allocator.h"
#include "mca/mpool/base/base.h"
#include "mca/mpool/mpool.h"
#include "mca/ptl/ptl.h"
#include "mca/ptl/base/base.h"
#include "mca/pml/pml.h"
#include "mca/pml/base/base.h"
#include "mca/coll/coll.h"
#include "mca/coll/base/base.h"
#include "mca/io/io.h"
#include "mca/io/base/base.h"
#include "mca/oob/oob.h"
#include "mca/oob/base/base.h"
#include "mca/ns/ns.h"
#include "mca/gpr/gpr.h"
#include "mca/rml/rml.h"
#include "mca/soh/soh.h"
#include "mca/errmgr/errmgr.h"
#include "runtime/runtime.h"
#include "event/event.h"
/*
* Global variables and symbols for the MPI layer
*/
bool ompi_mpi_initialized = false;
bool ompi_mpi_finalized = false;
bool ompi_mpi_thread_multiple = false;
int ompi_mpi_thread_requested = MPI_THREAD_SINGLE;
int ompi_mpi_thread_provided = MPI_THREAD_SINGLE;
ompi_thread_t *ompi_mpi_main_thread = NULL;
int ompi_mpi_init(int argc, char **argv, int requested, int *provided)
{
int ret, param;
bool allow_multi_user_threads;
bool have_hidden_threads;
bool compound_cmd=false;
ompi_proc_t** procs;
size_t nprocs;
char *error = NULL;
/* Join the run-time environment - do the things that don't hit the registry */
if (ORTE_SUCCESS != (ret = orte_init_stage1())) {
error = "ompi_mpi_init: orte_init_stage1 failed";
goto error;
}
/* if we are not the seed nor a singleton, AND we have not set the
* orte_debug flag, then
* start recording the compound command that starts us up.
* if we are the seed or a singleton, then don't do this - the registry is
* local, so we'll just drive it directly */
if (orte_process_info.seed ||
NULL == orte_process_info.ns_replica ||
orte_debug_flag) {
compound_cmd = false;
} else {
if (ORTE_SUCCESS != (ret = orte_gpr.begin_compound_cmd())) {
ORTE_ERROR_LOG(ret);
error = "ompi_mpi_init: orte_gpr.begin_compound_cmd failed";
goto error;
}
compound_cmd = true;
}
2004-09-23 18:35:02 +04:00
/* Now do the things that hit the registry */
if (ORTE_SUCCESS != (ret = orte_init_stage2())) {
ORTE_ERROR_LOG(ret);
error = "ompi_mpi_init: orte_init_stage2 failed";
goto error;
}
/* Once we've joined the RTE, see if any MCA parameters were
passed to the MPI level */
if (OMPI_SUCCESS != (ret = ompi_mpi_register_params())) {
error = "mca_mpi_register_params() failed";
goto error;
}
#ifndef WIN32
if (OMPI_SUCCESS != (ret = ompi_util_register_stackhandlers ())) {
error = "util_register_stackhandlers() failed";
goto error;
}
#endif
/* initialize ompi procs */
if (OMPI_SUCCESS != (ret = ompi_proc_init())) {
error = "mca_proc_init() failed";
goto error;
}
/* Open up MPI-related MCA modules. */
if (OMPI_SUCCESS != (ret = mca_allocator_base_open())) {
error = "mca_allocator_base_open() failed";
goto error;
}
if (OMPI_SUCCESS != (ret = mca_mpool_base_open())) {
error = "mca_mpool_base_open() failed";
goto error;
}
if (OMPI_SUCCESS != (ret = mca_pml_base_open())) {
error = "mca_pml_base_open() failed";
goto error;
}
if (OMPI_SUCCESS != (ret = mca_ptl_base_open())) {
error = "mca_ptl_base_open() failed";
goto error;
}
if (OMPI_SUCCESS != (ret = mca_coll_base_open())) {
error = "mca_coll_base_open() failed";
goto error;
}
/* The io framework is initialized lazily, at the first use of any
MPI_File_* function, so it is not included here. */
/* initialize module exchange */
if (OMPI_SUCCESS != (ret = mca_base_modex_init())) {
error = "mca_base_modex_init() failed";
goto error;
}
/* Select which pml, ptl, and coll modules to use, and determine the
2004-09-10 07:21:03 +04:00
final thread level */
if (OMPI_SUCCESS !=
2004-09-10 07:21:03 +04:00
(ret = mca_base_init_select_components(requested,
allow_multi_user_threads,
have_hidden_threads,
provided))) {
error = "mca_base_init_select_components() failed";
goto error;
}
/* initialize requests */
if (OMPI_SUCCESS != (ret = ompi_request_init())) {
error = "ompi_request_init() failed";
goto error;
}
/* initialize info */
if (OMPI_SUCCESS != (ret = ompi_info_init())) {
error = "ompi_info_init() failed";
goto error;
}
/* initialize error handlers */
if (OMPI_SUCCESS != (ret = ompi_errhandler_init())) {
error = "ompi_errhandler_init() failed";
goto error;
}
/* initialize error codes */
if (OMPI_SUCCESS != (ret = ompi_mpi_errcode_init())) {
error = "ompi_mpi_errcode_init() failed";
goto error;
}
/* initialize error classes */
if (OMPI_SUCCESS != (ret = ompi_errclass_init())) {
error = "ompi_errclass_init() failed";
goto error;
}
/* initialize internal error codes */
if (OMPI_SUCCESS != (ret = ompi_errcode_intern_init())) {
error = "ompi_errcode_intern_init() failed";
goto error;
}
/* initialize groups */
if (OMPI_SUCCESS != (ret = ompi_group_init())) {
error = "ompi_group_init() failed";
goto error;
}
/* initialize communicators */
if (OMPI_SUCCESS != (ret = ompi_comm_init())) {
error = "ompi_comm_init() failed";
goto error;
}
/* initialize datatypes */
if (OMPI_SUCCESS != (ret = ompi_ddt_init())) {
error = "ompi_ddt_init() failed";
goto error;
}
/* initialize ops */
if (OMPI_SUCCESS != (ret = ompi_op_init())) {
error = "ompi_op_init() failed";
goto error;
}
/* initialize file handles */
if (OMPI_SUCCESS != (ret = ompi_file_init())) {
error = "ompi_file_init() failed";
goto error;
}
/* initialize attribute meta-data structure for comm/win/dtype */
if (OMPI_SUCCESS != (ret = ompi_attr_init())) {
error = "ompi_attr_init() failed";
goto error;
}
/* do module exchange */
if (OMPI_SUCCESS != (ret = mca_base_modex_exchange())) {
error = "ompi_base_modex_exchange() failed";
goto error;
}
/*
* Let system know we are at STG1 Barrier
*/
if (ORTE_SUCCESS != (ret = orte_soh.set_proc_soh(orte_process_info.my_name,
ORTE_PROC_STATE_AT_STG1, 0))) {
ORTE_ERROR_LOG(ret);
error = "set process state failed";
goto error;
}
/* if the compound command is operative, execute it
*/
if (compound_cmd) {
if (OMPI_SUCCESS != (ret = orte_gpr.exec_compound_cmd())) {
ORTE_ERROR_LOG(ret);
error = "ompi_rte_init: orte_gpr.exec_compound_cmd failed";
goto error;
}
}
/* FIRST BARRIER - WAIT FOR MSG FROM RMGR_PROC_STAGE_GATE_MGR TO ARRIVE */
if (ORTE_SUCCESS != (ret = orte_rml.xcast(NULL, NULL, 0, NULL, NULL))) {
ORTE_ERROR_LOG(ret);
error = "ompi_mpi_init: failed to see all procs register\n";
goto error;
}
if (orte_debug_flag) {
ompi_output(0, "[%d,%d,%d] process startup completed",
ORTE_NAME_ARGS(orte_process_info.my_name));
}
/* add all ompi_proc_t's to PML */
if (NULL == (procs = ompi_proc_world(&nprocs))) {
error = "ompi_proc_world() failed";
goto error;
}
if (OMPI_SUCCESS != (ret = mca_pml.pml_add_procs(procs, nprocs))) {
free(procs);
error = "PML add procs failed";
goto error;
}
free(procs);
/* start PTL's */
param = 1;
if (OMPI_SUCCESS !=
(ret = mca_pml.pml_control(MCA_PTL_ENABLE, &param, sizeof(param)))) {
error = "PML control failed";
goto error;
}
/* save the resulting thread levels */
ompi_mpi_thread_requested = requested;
ompi_mpi_thread_provided = *provided;
ompi_mpi_thread_multiple = (ompi_mpi_thread_provided ==
MPI_THREAD_MULTIPLE);
#if OMPI_ENABLE_MPI_THREADS
ompi_mpi_main_thread = ompi_thread_get_self();
#else
ompi_mpi_main_thread = NULL;
#endif
/* Init coll for the comms */
if (OMPI_SUCCESS !=
(ret = mca_coll_base_comm_select(MPI_COMM_SELF, NULL))) {
error = "mca_coll_base_comm_select(MPI_COMM_SELF) failed";
goto error;
}
if (OMPI_SUCCESS !=
(ret = mca_coll_base_comm_select(MPI_COMM_WORLD, NULL))) {
error = "mca_coll_base_comm_select(MPI_COMM_WORLD) failed";
goto error;
}
#if OMPI_ENABLE_PROGRESS_THREADS /* BWB - XXX - FIXME - is this actually correct? */
/* setup I/O forwarding */
if (ompi_process_info.seed == false) {
if (OMPI_SUCCESS != (ret = ompi_mpi_init_io())) {
error = "ompi_rte_init_io failed";
goto error;
}
}
#endif
/*
* Let system know we are at STG2 Barrier
*/
if (ORTE_SUCCESS != (ret = orte_soh.set_proc_soh(orte_process_info.my_name,
ORTE_PROC_STATE_AT_STG2, 0))) {
ORTE_ERROR_LOG(ret);
error = "set process state failed";
goto error;
}
/* BWB - is this still needed? */
#if OMPI_ENABLE_PROGRESS_THREADS == 0
ompi_progress_events(OMPI_EVLOOP_NONBLOCK);
#endif
/* SECOND BARRIER - WAIT FOR MSG FROM RMGR_PROC_STAGE_GATE_MGR TO ARRIVE */
if (ORTE_SUCCESS != (ret = orte_rml.xcast(NULL, NULL, 0, NULL, NULL))) {
ORTE_ERROR_LOG(ret);
error = "ompi_mpi_init: failed to see all procs register\n";
goto error;
}
/* new very last step: check whether we have been spawned or not.
We introduce that at the very end, since we need collectives,
datatypes, ptls etc. up and running here....
*/
if (OMPI_SUCCESS != (ret = ompi_comm_dyn_init())) {
error = "ompi_comm_dyn_init() failed";
goto error;
}
error:
if (ret != OMPI_SUCCESS) {
ompi_show_help("help-mpi-runtime",
"mpi_init:startup:internal-failure", true,
"MPI_INIT", "MPI_INIT", error, ret);
return ret;
}
/* All done */
ompi_mpi_initialized = true;
ompi_mpi_finalized = false;
if (orte_debug_flag) {
ompi_output(0, "[%d,%d,%d] ompi_mpi_init completed",
ORTE_NAME_ARGS(orte_process_info.my_name));
}
return MPI_SUCCESS;
}