|
| 1 | +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ |
| 2 | +/* |
| 3 | + * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana |
| 4 | + * University Research and Technology |
| 5 | + * Corporation. All rights reserved. |
| 6 | + * Copyright (c) 2004-2017 The University of Tennessee and The University |
| 7 | + * of Tennessee Research Foundation. All rights |
| 8 | + * reserved. |
| 9 | + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, |
| 10 | + * University of Stuttgart. All rights reserved. |
| 11 | + * Copyright (c) 2004-2005 The Regents of the University of California. |
| 12 | + * All rights reserved. |
| 13 | + * Copyright (c) 2009 Cisco Systems, Inc. All rights reserved. |
| 14 | + * Copyright (c) 2016 Research Organization for Information Science |
| 15 | + * and Technology (RIST). All rights reserved. |
| 16 | + * Copyright (c) 2018 Intel, Inc. All rights reserved. |
| 17 | + * Copyright (c) 2018 Triad National Security, LLC. All rights |
| 18 | + * reserved. |
| 19 | + * $COPYRIGHT$ |
| 20 | + * |
| 21 | + * Additional copyrights may follow |
| 22 | + * |
| 23 | + * $HEADER$ |
| 24 | + */ |
| 25 | + |
| 26 | +#include "ompi_config.h" |
| 27 | + |
| 28 | +#ifdef HAVE_STRING_H |
| 29 | +#include <string.h> |
| 30 | +#endif |
| 31 | +#include <stdio.h> |
| 32 | + |
| 33 | +#include "coll_lazy.h" |
| 34 | + |
| 35 | +#include "mpi.h" |
| 36 | + |
| 37 | +#include "opal/util/show_help.h" |
| 38 | +#include "ompi/mca/rte/rte.h" |
| 39 | + |
| 40 | +#include "ompi/constants.h" |
| 41 | +#include "ompi/communicator/communicator.h" |
| 42 | +#include "ompi/mca/coll/coll.h" |
| 43 | +#include "ompi/mca/coll/base/base.h" |
| 44 | +#include "coll_lazy.h" |
| 45 | + |
| 46 | + |
| 47 | +static void mca_coll_lazy_module_construct(mca_coll_lazy_module_t *module) |
| 48 | +{ |
| 49 | + module->pth_barrier_init = false; |
| 50 | +} |
| 51 | + |
| 52 | +static void mca_coll_lazy_module_destruct(mca_coll_lazy_module_t *module) |
| 53 | +{ |
| 54 | + if (module->pth_barrier_init) { |
| 55 | + pthread_barrier_destroy (&module->pth_barrier); |
| 56 | + module->pth_barrier_init = false; |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +OBJ_CLASS_INSTANCE(mca_coll_lazy_module_t, mca_coll_base_module_t, |
| 61 | + mca_coll_lazy_module_construct, |
| 62 | + mca_coll_lazy_module_destruct); |
| 63 | + |
| 64 | + |
| 65 | +/* |
| 66 | + * Initial query function that is invoked during MPI_INIT, allowing |
| 67 | + * this component to disqualify itself if it doesn't support the |
| 68 | + * required level of thread support. |
| 69 | + */ |
| 70 | +int mca_coll_lazy_init_query(bool enable_progress_threads, |
| 71 | + bool enable_mpi_threads) |
| 72 | +{ |
| 73 | + /* Nothing to do */ |
| 74 | + return OMPI_SUCCESS; |
| 75 | +} |
| 76 | + |
| 77 | + |
| 78 | +/* |
| 79 | + * Invoked when there's a new communicator that has been created. |
| 80 | + * Look at the communicator and decide which set of functions and |
| 81 | + * priority we want to return. |
| 82 | + */ |
| 83 | +mca_coll_base_module_t *mca_coll_lazy_comm_query (ompi_communicator_t *comm, int *priority) |
| 84 | +{ |
| 85 | + mca_coll_lazy_module_t *lazy_module; |
| 86 | + |
| 87 | + *priority = 0; |
| 88 | + |
| 89 | + if (ompi_group_have_remote_peers (comm->c_local_group) || !OMPI_COMM_CHECK_ASSERT_LAZY_BARRIER(comm)) { |
| 90 | + return NULL; |
| 91 | + } |
| 92 | + |
| 93 | + lazy_module = OBJ_NEW(mca_coll_lazy_module_t); |
| 94 | + if (NULL == lazy_module) { |
| 95 | + return NULL; |
| 96 | + } |
| 97 | + |
| 98 | + *priority = mca_coll_lazy_component.priority; |
| 99 | + |
| 100 | + /* Choose whether to use [intra|inter] */ |
| 101 | + lazy_module->super.coll_module_enable = mca_coll_lazy_module_enable; |
| 102 | + |
| 103 | + lazy_module->super.coll_barrier = mca_coll_lazy_barrier; |
| 104 | + |
| 105 | + return &lazy_module->super; |
| 106 | +} |
| 107 | + |
| 108 | + |
| 109 | +/* |
| 110 | + * Init module on the communicator |
| 111 | + */ |
| 112 | +int mca_coll_lazy_module_enable (mca_coll_base_module_t *module, ompi_communicator_t *comm) |
| 113 | +{ |
| 114 | + mca_coll_lazy_module_t *lazy_module = (mca_coll_lazy_module_t *) module; |
| 115 | + int rc; |
| 116 | + |
| 117 | + rc = pthread_barrier_init (&lazy_module->pth_barrier, NULL, comm->c_local_group->grp_proc_count); |
| 118 | + if (0 != rc) { |
| 119 | + return OMPI_ERR_NOT_FOUND; |
| 120 | + } |
| 121 | + |
| 122 | + lazy_module->pth_barrier_init = true; |
| 123 | + |
| 124 | + return OMPI_SUCCESS; |
| 125 | +} |
0 commit comments