1
1

Add an example on how to handle topologies.

This commit was SVN r32337.
Этот коммит содержится в:
George Bosilca 2014-07-29 05:05:59 +00:00
родитель d674e22433
Коммит 78eae6108a
8 изменённых файлов: 450 добавлений и 0 удалений

0
ompi/mca/topo/example/.ompi_ignore Обычный файл
Просмотреть файл

54
ompi/mca/topo/example/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,54 @@
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2013 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2009 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 (c) 2009 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2012-2013 Inria. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
EXTRA_DIST = .windows
sources = \
topo_example.h \
topo_example_cart_map.c \
topo_example_graph_map.c \
topo_example_module.c \
topo_example_component.c
# Make the output library in this directory, and name it either
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
# (for static builds).
if MCA_BUILD_ompi_topo_example_DSO
lib =
lib_sources =
component = mca_topo_example.la
component_sources = $(sources)
else
lib = libmca_topo_example.la
lib_sources = $(sources)
component =
component_sources =
endif
mcacomponentdir = $(pkglibdir)
mcacomponent_LTLIBRARIES = $(component)
mca_topo_example_la_SOURCES = $(component_sources)
mca_topo_example_la_LDFLAGS = -module -avoid-version
noinst_LTLIBRARIES = $(lib)
libmca_topo_example_la_SOURCES = $(lib_sources)
libmca_topo_example_la_LDFLAGS = -module -avoid-version

25
ompi/mca/topo/example/configure.params Обычный файл
Просмотреть файл

@ -0,0 +1,25 @@
# -*- shell-script -*-
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. 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 (c) 2007 Los Alamos National Security, LLC. All rights
# reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# Specific to this module
PARAM_CONFIG_FILES="Makefile"

86
ompi/mca/topo/example/topo_example.h Обычный файл
Просмотреть файл

@ -0,0 +1,86 @@
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2013 The University of Tennessee and The University
* of Tennessee Research Foundation. 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 (c) 2009 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Inria. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef MCA_TOPO_UNTIY_H
#define MCA_TOPO_UNTIY_H
#include "ompi_config.h"
#include "ompi/mca/topo/topo.h"
/*
* ******************************************************************
* ******** functions which provide MCA interface comppliance *******
* ******************************************************************
* These functions are:
* - mca_topo_example_module_open
* - mca_topo_example_module_close
* - mca_topo_example_module_query
* - mca_topo_example_module_finalize
* These functions are always found on the mca_topo_example_module
* structure. They are the "meta" functions to ensure smooth op.
* ******************************************************************
*/
BEGIN_C_DECLS
/*
* Public component instance
*/
OMPI_MODULE_DECLSPEC extern mca_topo_base_component_2_1_0_t
mca_topo_example_component;
/*
* A unique module class for the module so that we can both cache
* module-specific information on the module and have a
* module-specific constructor and destructor.
*/
typedef struct {
mca_topo_base_module_t super;
/* Modules can add their own information here */
int example_module_specific_data;
} mca_topo_example_module_t;
OBJ_CLASS_DECLARATION(mca_topo_example_module_t);
/*
* Module functions
*/
int mca_topo_example_cart_map(struct ompi_communicator_t *comm,
int ndims,
int *dims,
int *periods,
int *newrank);
int mca_topo_example_graph_map(struct ompi_communicator_t *comm,
int nnodes,
int *index,
int *edges,
int *newrank);
/*
* ******************************************************************
* ************ functions implemented in this module end ************
* ******************************************************************
*/
END_C_DECLS
#endif /* MCA_TOPO_EXAMPLE_H */

Просмотреть файл

@ -0,0 +1,79 @@
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2013 The University of Tennessee and The University
* of Tennessee Research Foundation. 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 (c) 2009 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Inria. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "ompi/mca/topo/example/topo_example.h"
#include "ompi/communicator/communicator.h"
/*
* function - mca_topo_example_cart_map
*
* @param comm input communicator (handle)
* @param ndims number of dimensions of cartesian structure (integer)
* @param dims integer array of size 'ndims' specifying the number of
* processes in each coordinate direction
* @param periods logical array of size 'ndims' specifying the
* periodicity specification in each coordinate direction
* @param newrank reordered rank of the calling process; 'MPI_UNDEFINED'
* if calling process does not belong to grid (integer)
*
* @retval MPI_SUCCESS
* @retval MPI_ERR_DIMS
*/
int mca_topo_example_cart_map (ompi_communicator_t* comm,
int ndims,
int *dims,
int *periods,
int *newrank)
{
int nprocs;
int rank;
int size;
int i;
int *p;
/*
* Compute the # of processes in the grid.
*/
nprocs = 1;
for (i = 0, p = dims; i < ndims; ++i, ++p) {
if (*p <= 0) {
return MPI_ERR_DIMS;
}
nprocs *= *p;
}
/*
* Check that number of processes <= size of communicator.
*/
size = ompi_comm_size(comm);
if (nprocs > size) {
return MPI_ERR_DIMS;
}
/*
* Compute my new rank. To be slightly different than the "unity"
* component, start with a rank that is size-my_initial_rank.
*/
rank = ompi_comm_size(comm) - 1 - ompi_comm_rank(comm);
*newrank = ((rank < 0) || (rank >= nprocs)) ? MPI_UNDEFINED : rank;
return MPI_SUCCESS;
}

Просмотреть файл

@ -0,0 +1,90 @@
/*
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2013 The University of Tennessee and The University
* of Tennessee Research Foundation. 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 (c) 2009 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Inria. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "ompi/mca/topo/example/topo_example.h"
/*
* Public string showing the topo example module version number
*/
const char *mca_topo_example_component_version_string =
"Open MPI example topology MCA component version" OMPI_VERSION;
/*
* Local funtions
*/
static int init_query(bool enable_progress_threads, bool enable_mpi_threads);
static struct mca_topo_base_module_t *
comm_query(const ompi_communicator_t *comm, int *priority, uint32_t type);
/*
* Public component structure
*/
mca_topo_base_component_2_1_0_t mca_topo_example_component =
{
{
MCA_TOPO_BASE_VERSION_2_1_0,
"example",
OMPI_MAJOR_VERSION,
OMPI_MINOR_VERSION,
OMPI_RELEASE_VERSION,
/* NULLs for the rest of the function pointers */
},
{
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
init_query,
comm_query
};
static int init_query(bool enable_progress_threads, bool enable_mpi_threads)
{
/* Nothing to do */
return OMPI_SUCCESS;
}
static struct mca_topo_base_module_t *
comm_query(const ompi_communicator_t *comm, int *priority, uint32_t type)
{
mca_topo_example_module_t *example = OBJ_NEW(mca_topo_example_module_t);
if (NULL == example) {
return NULL;
}
if( OMPI_COMM_CART == type ) {
example->super.topo.cart.cart_map = mca_topo_example_cart_map;
} else if( OMPI_COMM_GRAPH == type ) {
example->super.topo.graph.graph_map = mca_topo_example_graph_map;
}
/* This component has very low priority -- it's an example, after all! */
*priority = 0;
example->super.type = type;
return &(example->super);
}

Просмотреть файл

@ -0,0 +1,58 @@
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2013 The University of Tennessee and The University
* of Tennessee Research Foundation. 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 (c) 2009 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Inria. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "ompi/mca/topo/example/topo_example.h"
#include "ompi/communicator/communicator.h"
/*
* function - mca_topo_example_graph_map
*
* @param comm input communicator (handle)
* @param nnodes number of graph nodes (integer)
* @param index integer array specifying the graph structure
* @param edges integer array specifying the graph structure
* @param newrank reordered rank of the calling process; 'MPI_UNDEFINED'
* if the calling process does not belong to
* graph (integer)
*
* @retval MPI_SUCCESS
* @retval MPI_UNDEFINED
*/
int mca_topo_example_graph_map (ompi_communicator_t* comm,
int nnodes,
int *index,
int *edges,
int *newrank)
{
int myrank;
/*
* Compute my new rank. To be slightly different than the "unity"
* component, start with a rank that is size-my_initial_rank.
*/
myrank = ompi_comm_size(comm) - 1 - ompi_comm_rank(comm);
*newrank =
((0 > myrank) || (myrank >= nnodes)) ? MPI_UNDEFINED : myrank;
return OMPI_SUCCESS;
}

58
ompi/mca/topo/example/topo_example_module.c Обычный файл
Просмотреть файл

@ -0,0 +1,58 @@
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2013 The University of Tennessee and The University
* of Tennessee Research Foundation. 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 (c) 2008-2009 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Inria. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include <stdio.h>
#include "mpi.h"
#include "ompi/communicator/communicator.h"
#include "ompi/mca/topo/topo.h"
#include "ompi/mca/topo/base/base.h"
#include "ompi/mca/topo/example/topo_example.h"
/*
* Local functions
*/
static void example_module_constructor(mca_topo_example_module_t *u);
static void example_module_destructor(mca_topo_example_module_t *u);
OBJ_CLASS_INSTANCE(mca_topo_example_module_t, mca_topo_base_module_t,
example_module_constructor, example_module_destructor);
static void example_module_constructor(mca_topo_example_module_t *u)
{
mca_topo_base_module_t *m = &(u->super);
memset(&m->topo, 0, sizeof(m->topo));
/* Here we can fill in additional, module-specific data if
necessary */
u->example_module_specific_data = 17;
}
static void example_module_destructor(mca_topo_example_module_t *u)
{
/* Do whatever is necessary to clean up / destroy the module */
}