2007-07-21 01:36:11 +04:00
/*
2007-07-26 02:28:04 +04:00
* Copyright ( c ) 2004 - 2007 The Trustees of the University of Tennessee .
2007-07-21 01:36:11 +04:00
* All rights reserved .
* $ COPYRIGHT $
*
* Additional copyrights may follow
*
* $ HEADER $
*/
2007-07-26 02:28:04 +04:00
2007-07-21 01:36:11 +04:00
# include "ompi_config.h"
# include "opal/mca/base/mca_base_param.h"
# include "opal/mca/base/base.h"
# include "opal/mca/base/mca_base_component_repository.h"
2007-08-16 09:52:30 +04:00
# include "ompi/constants.h"
2007-07-21 01:36:11 +04:00
# include "ompi/mca/pml/base/base.h"
# include "pml_v.h"
2008-01-29 09:07:57 +03:00
# include "mca/vprotocol/vprotocol.h"
# include "mca/vprotocol/base/base.h"
2007-07-21 01:36:11 +04:00
static int mca_pml_v_component_open ( void ) ;
static int mca_pml_v_component_close ( void ) ;
static int mca_pml_v_component_parasite_close ( void ) ;
2007-07-28 03:11:00 +04:00
static mca_pml_base_module_t * mca_pml_v_component_init ( int * priority , bool enable_threads , bool enable_progress_threads ) ;
2007-07-21 01:36:11 +04:00
static int mca_pml_v_component_finalize ( void ) ;
static int mca_pml_v_component_parasite_finalize ( void ) ;
2007-08-16 09:52:30 +04:00
static int mca_pml_v_enable ( bool enable ) ;
2007-07-21 01:36:11 +04:00
static inline int mca_pml_v_param_register_int ( const char * param_name , int default_value ) ;
static inline char * mca_pml_v_param_register_string ( const char * param_name , char * default_value ) ;
mca_pml_base_component_1_0_0_t mca_pml_v_component =
{
/* First, the mca_base_component_t struct containing meta
* information about the component itself */
{
MCA_PML_BASE_VERSION_1_0_0 , /* Indicate that we are a pml v1.0.0 component (which also implies a specific MCA version) */
" v " , /* MCA component name */
1 , /* MCA component major version */
0 , /* MCA component minor version */
0 , /* MCA component release version */
mca_pml_v_component_open ,
mca_pml_v_component_close
} ,
/* Next the MCA v1.0.0 component meta data */
{
false /* Whether the component is checkpointable or not */
} ,
mca_pml_v_component_init , /* component init */
mca_pml_v_component_finalize /* component finalize */
} ;
2007-08-16 09:52:30 +04:00
static bool pml_v_enable_progress_treads = OMPI_ENABLE_PROGRESS_THREADS ;
static bool pml_v_enable_mpi_threads = OMPI_ENABLE_MPI_THREADS ;
/*******************************************************************************
* MCA level functions - parasite setup
2007-07-28 03:11:00 +04:00
*/
2007-07-21 01:36:11 +04:00
static int mca_pml_v_component_open ( void )
{
2007-07-28 03:11:00 +04:00
char * output ;
int verbose ;
2007-08-16 09:52:30 +04:00
int priority ;
2007-09-13 00:47:17 +04:00
char * vprotocol_include_list ;
2007-08-16 09:52:30 +04:00
priority = mca_pml_v_param_register_int ( " priority " , - 1 ) ;
2007-07-28 03:11:00 +04:00
output = mca_pml_v_param_register_string ( " output " , " stderr " ) ;
verbose = mca_pml_v_param_register_int ( " verbose " , 0 ) ;
2007-07-21 01:36:11 +04:00
2007-09-13 00:47:17 +04:00
mca_base_param_reg_string_name ( " vprotocol " , NULL ,
" Specify a specific vprotocol to use " ,
false , false , " " , & vprotocol_include_list ) ;
2007-08-16 09:52:30 +04:00
pml_v_output_open ( output , verbose ) ;
2007-07-21 01:36:11 +04:00
2007-08-16 09:52:30 +04:00
if ( - 1 ! = priority )
V_OUTPUT_ERR ( " pml_v: Overriding priority setting (%d) with -1. The PML V should NEVER be the selected component; even when enabling fault tolerance. " , priority ) ;
2007-07-31 23:33:39 +04:00
V_OUTPUT_VERBOSE ( 500 , " loaded " ) ;
2007-09-13 00:47:17 +04:00
return mca_vprotocol_base_open ( vprotocol_include_list ) ;
2007-07-28 03:11:00 +04:00
}
2007-07-21 01:36:11 +04:00
static int mca_pml_v_component_close ( void )
2007-08-16 09:52:30 +04:00
{
int ret ;
2007-09-13 00:47:17 +04:00
2007-08-16 09:52:30 +04:00
/* Save original PML before making any changes */
2007-07-21 01:36:11 +04:00
mca_pml_v . host_pml_component = mca_pml_base_selected_component ;
2007-08-16 09:52:30 +04:00
mca_pml_v . host_pml = mca_pml ;
2007-12-07 11:21:25 +03:00
mca_pml_v . host_request_fns = ompi_request_functions ;
2007-09-13 00:47:17 +04:00
/* Do not load anything if no FT protocol is selected */
if ( ! mca_vprotocol_base_include_list [ 0 ] )
return mca_pml_v_component_parasite_close ( ) ;
V_OUTPUT_VERBOSE ( 500 , " component_close: I don't want to be unloaded now. " ) ;
2007-08-16 09:52:30 +04:00
ret = mca_base_component_repository_retain_component ( " pml " , " v " ) ;
if ( OPAL_SUCCESS ! = ret )
2007-07-21 01:36:11 +04:00
{
2008-01-30 13:41:49 +03:00
V_OUTPUT_ERR ( " pml_v: component_close: can't retain myself. If Open MPI is build static you can ignore this error. Otherwise it should crash soon. " ) ;
2007-07-21 01:36:11 +04:00
}
2007-08-16 09:52:30 +04:00
/* Mark that we have changed something */
snprintf ( mca_pml_base_selected_component . pmlm_version . mca_component_name ,
MCA_BASE_MAX_TYPE_NAME_LEN , " %s]v%s " ,
mca_pml_v . host_pml_component . pmlm_version . mca_component_name ,
mca_vprotocol_component . pmlm_version . mca_component_name ) ;
/* Replace finalize */
mca_pml_base_selected_component . pmlm_finalize =
mca_pml_v_component_parasite_finalize ;
/* Make sure we get initialized if some Vprotocol is enabled */
mca_pml . pml_enable = mca_pml_v_enable ;
2007-07-21 01:36:11 +04:00
return OMPI_SUCCESS ;
}
2007-08-16 09:52:30 +04:00
/*******************************************************************************
* Parasite cleanup
*/
static int mca_pml_v_component_parasite_finalize ( void )
{
mca_base_component_list_item_t * cli = NULL ;
V_OUTPUT_VERBOSE ( 500 , " parasite_finalize " ) ;
/* Make sure we'll get closed again with the true close function */
mca_pml_v_component . pmlm_version . mca_close_component =
mca_pml_v_component_parasite_close ;
cli = OBJ_NEW ( mca_base_component_list_item_t ) ;
cli - > cli_component = ( mca_base_component_t * ) & mca_pml_v_component ;
opal_list_prepend ( & mca_pml_base_components_available ,
( opal_list_item_t * ) cli ) ;
/* finalize vprotocol component */
if ( mca_vprotocol_base_selected ( ) )
mca_vprotocol_component . pmlm_finalize ( ) ;
if ( mca_pml_v . host_pml_component . pmlm_finalize ! = NULL )
return mca_pml_v . host_pml_component . pmlm_finalize ( ) ;
else
return OMPI_SUCCESS ;
}
2007-07-21 01:36:11 +04:00
static int mca_pml_v_component_parasite_close ( void )
{
2007-09-13 00:47:17 +04:00
V_OUTPUT_VERBOSE ( 500 , " parasite_close: Ok, I accept to die and let %s component finish " ,
2007-07-30 23:11:15 +04:00
mca_pml_v . host_pml_component . pmlm_version . mca_component_name ) ;
mca_pml_base_selected_component = mca_pml_v . host_pml_component ;
2007-07-21 01:36:11 +04:00
2007-08-16 09:52:30 +04:00
mca_vprotocol_base_close ( ) ;
pml_v_output_close ( ) ;
2007-07-21 01:36:11 +04:00
2007-08-16 09:52:30 +04:00
mca_pml . pml_enable = mca_pml_v . host_pml . pml_enable ;
/* don't need to call the host component's close: pml_base will do it */
return OMPI_SUCCESS ; /* ignore any errors as we are leaving anyway */
2007-07-21 01:36:11 +04:00
}
2007-08-16 09:52:30 +04:00
/*******************************************************************************
* Init / finalize for MCA PML components
*/
2007-07-21 01:36:11 +04:00
static mca_pml_base_module_t * mca_pml_v_component_init ( int * priority ,
bool enable_progress_threads ,
bool enable_mpi_threads )
{
2007-08-16 09:52:30 +04:00
V_OUTPUT_VERBOSE ( 1 , " init: I'm not supposed to be here until BTL loading stuff gets fixed!? That's strange... " ) ;
pml_v_enable_progress_treads = enable_progress_threads ;
pml_v_enable_mpi_threads = enable_mpi_threads ;
/* I NEVER want to be the selected PML, so I report less than possible
* priority and a NULL module
*/
* priority = - 1 ;
return NULL ;
2007-07-21 01:36:11 +04:00
}
static int mca_pml_v_component_finalize ( void )
{
2007-08-16 09:52:30 +04:00
V_OUTPUT_VERBOSE ( 1 , " finalize: I'm not supposed to be here until BTL loading stuff gets fixed!? That's strange... " ) ;
/* Nothing to do here. We are not sure we need to be unloaded or not at
* this stage
*/
return OMPI_SUCCESS ;
2007-07-21 01:36:11 +04:00
}
2007-08-16 09:52:30 +04:00
/*******************************************************************************
* Enable the PML V ( and initialize the Vprotocol )
*/
static int mca_pml_v_enable ( bool enable )
{
int ret ;
/* Enable the real PML (no threading issues there as threads are started
2007-09-21 01:57:21 +04:00
* later )
2007-08-16 09:52:30 +04:00
*/
ret = mca_pml_v . host_pml . pml_enable ( enable ) ;
if ( OMPI_SUCCESS ! = ret ) return ret ;
if ( enable ) {
2007-09-21 01:57:21 +04:00
/* Check if a protocol have been selected during init */
if ( ! mca_vprotocol_base_selected ( ) )
mca_vprotocol_base_select ( pml_v_enable_progress_treads ,
pml_v_enable_mpi_threads ) ;
2007-08-16 09:52:30 +04:00
2007-09-21 01:57:21 +04:00
/* Check if we succeeded selecting a protocol */
2007-08-16 09:52:30 +04:00
if ( mca_vprotocol_base_selected ( ) ) {
V_OUTPUT_VERBOSE ( 1 , " I don't want to die: I will parasite %s host component %s with %s %s " ,
mca_pml_base_selected_component . pmlm_version . mca_type_name ,
mca_pml_base_selected_component . pmlm_version . mca_component_name ,
mca_vprotocol_component . pmlm_version . mca_type_name ,
mca_vprotocol_component . pmlm_version . mca_component_name ) ;
ret = mca_vprotocol_base_parasite ( ) ;
if ( OMPI_SUCCESS ! = ret ) return ret ;
if ( mca_vprotocol . enable )
return mca_vprotocol . enable ( enable ) ;
else
return OMPI_SUCCESS ;
}
V_OUTPUT_VERBOSE ( 1 , " No fault tolerant protocol selected. All are unloaded " ) ;
}
/* Disable */
mca_pml = mca_pml_v . host_pml ;
mca_pml . pml_enable = mca_pml_v_enable ;
2007-12-07 11:21:25 +03:00
/* /!\ This is incorrect if another component also changed the requests */
ompi_request_functions = mca_pml_v . host_request_fns ;
2007-07-21 01:36:11 +04:00
return OMPI_SUCCESS ;
}
2007-08-16 09:52:30 +04:00
/*******************************************************************************
* utilities
*/
2007-07-21 01:36:11 +04:00
static inline int mca_pml_v_param_register_int ( const char * param_name ,
int default_value )
{
int id = mca_base_param_register_int ( " pml " , " v " , param_name , NULL , default_value ) ;
int param_value = default_value ;
mca_base_param_lookup_int ( id , & param_value ) ;
return param_value ;
}
static inline char * mca_pml_v_param_register_string ( const char * param_name ,
char * default_value )
{
int id = mca_base_param_register_string ( " pml " , " v " , param_name , NULL , default_value ) ;
char * param_value = default_value ;
mca_base_param_lookup_string ( id , & param_value ) ;
return param_value ;
}