1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2018 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) 2015-2018 Los Alamos National Security, LLC. All rights
14 * reserved.
15 * Copyright (c) 2018 Sandia National Laboratories
16 * All rights reserved.
17 * $COPYRIGHT$
18 *
19 * Additional copyrights may follow
20 *
21 * $HEADER$
22 */
23 /**
24 * @file
25 */
26 #ifndef MCA_PML_OB1_COMM_H
27 #define MCA_PML_OB1_COMM_H
28
29 #include "opal/threads/mutex.h"
30 #include "opal/class/opal_list.h"
31 #include "ompi/proc/proc.h"
32 #include "ompi/communicator/communicator.h"
33
34 /* NTH: at some point we need to untangle the headers. this declaration is needed
35 * for headers included by the custom match code. */
36 typedef struct mca_pml_ob1_comm_proc_t mca_pml_ob1_comm_proc_t;
37
38 #include "custommatch/pml_ob1_custom_match.h"
39
40 BEGIN_C_DECLS
41
42
43 struct mca_pml_ob1_comm_proc_t {
44 opal_object_t super;
45 struct ompi_proc_t* ompi_proc;
46 uint16_t expected_sequence; /**< send message sequence number - receiver side */
47 opal_atomic_int32_t send_sequence; /**< send side sequence number */
48 struct mca_pml_ob1_recv_frag_t* frags_cant_match; /**< out-of-order fragment queues */
49 #if !MCA_PML_OB1_CUSTOM_MATCH
50 opal_list_t specific_receives; /**< queues of unmatched specific receives */
51 opal_list_t unexpected_frags; /**< unexpected fragment queues */
52 #endif
53 };
54
55 OBJ_CLASS_DECLARATION(mca_pml_ob1_comm_proc_t);
56
57 /**
58 * Cached on ompi_communicator_t to hold queues/state
59 * used by the PML<->PTL interface for matching logic.
60 */
61 struct mca_pml_comm_t {
62 opal_object_t super;
63 volatile uint32_t recv_sequence; /**< recv request sequence number - receiver side */
64 opal_mutex_t matching_lock; /**< matching lock */
65 #if !MCA_PML_OB1_CUSTOM_MATCH
66 opal_list_t wild_receives; /**< queue of unmatched wild (source process not specified) receives */
67 #endif
68 opal_mutex_t proc_lock;
69 mca_pml_ob1_comm_proc_t **procs;
70 size_t num_procs;
71 size_t last_probed;
72 #if MCA_PML_OB1_CUSTOM_MATCH
73 custom_match_prq* prq;
74 custom_match_umq* umq;
75 #endif
76 };
77 typedef struct mca_pml_comm_t mca_pml_ob1_comm_t;
78
79 OBJ_CLASS_DECLARATION(mca_pml_ob1_comm_t);
80
81 static inline mca_pml_ob1_comm_proc_t *mca_pml_ob1_peer_lookup (struct ompi_communicator_t *comm, int rank)
82 {
83 mca_pml_ob1_comm_t *pml_comm = (mca_pml_ob1_comm_t *)comm->c_pml_comm;
84
85 /**
86 * We have very few ways to validate the correct, and collective, creation of
87 * the communicator, and ensure all processes have the same cid. The least we
88 * can do is to check that we are not using a rank that is outside the scope
89 * of the communicator.
90 */
91 if( OPAL_UNLIKELY(rank >= (int)pml_comm->num_procs) ) {
92 ompi_rte_abort(-1, "PML OB1 received a message from a rank outside the"
93 " valid range of the communicator. Please submit a bug request!");
94 }
95 if (OPAL_UNLIKELY(NULL == pml_comm->procs[rank])) {
96 OPAL_THREAD_LOCK(&pml_comm->proc_lock);
97 if (NULL == pml_comm->procs[rank]) {
98 mca_pml_ob1_comm_proc_t* proc = OBJ_NEW(mca_pml_ob1_comm_proc_t);
99 proc->ompi_proc = ompi_comm_peer_lookup (comm, rank);
100 OBJ_RETAIN(proc->ompi_proc);
101 opal_atomic_wmb ();
102 pml_comm->procs[rank] = proc;
103 }
104 OPAL_THREAD_UNLOCK(&pml_comm->proc_lock);
105 }
106
107 return pml_comm->procs[rank];
108 }
109
110 /**
111 * Initialize an instance of mca_pml_ob1_comm_t based on the communicator size.
112 *
113 * @param comm Instance of mca_pml_ob1_comm_t
114 * @param size Size of communicator
115 * @return OMPI_SUCCESS or error status on failure.
116 */
117
118 extern int mca_pml_ob1_comm_init_size(mca_pml_ob1_comm_t* comm, size_t size);
119
120 END_C_DECLS
121 #endif
122