OpenMPI  0.1.1
win.h
1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
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-2007 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) 2006 Cisco Systems, Inc. All rights reserved.
14  * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
15  * $COPYRIGHT$
16  *
17  * Additional copyrights may follow
18  *
19  * $HEADER$
20  */
21 
22 #ifndef OMPI_WIN_H
23 #define OMPI_WIN_H
24 
25 #include "ompi_config.h"
26 #include "mpi.h"
27 
28 #include "opal/class/opal_object.h"
31 #include "ompi/info/info.h"
32 #include "ompi/communicator/communicator.h"
33 #include "ompi/group/group.h"
34 #include "ompi/mca/osc/osc.h"
35 
36 BEGIN_C_DECLS
37 
38 /* flags */
39 #define OMPI_WIN_FREED 0x00000001
40 #define OMPI_WIN_INVALID 0x00000002
41 #define OMPI_WIN_NO_LOCKS 0x00000004
42 
43 /* mode */
44 #define OMPI_WIN_ACCESS_EPOCH 0x00000001
45 #define OMPI_WIN_EXPOSE_EPOCH 0x00000002
46 #define OMPI_WIN_FENCE 0x00000010
47 #define OMPI_WIN_POSTED 0x00000020
48 #define OMPI_WIN_STARTED 0x00000040
49 #define OMPI_WIN_LOCK_ACCESS 0x00000080
50 
51 OMPI_DECLSPEC extern opal_pointer_array_t ompi_mpi_windows;
52 
53 struct ompi_win_t {
54  opal_object_t w_base;
55 
56  opal_mutex_t w_lock;
57 
58  char w_name[MPI_MAX_OBJECT_NAME];
59 
60  /* Group associated with this window. */
61  ompi_group_t *w_group;
62 
63  /* Information about the state of the window. */
64  uint16_t w_flags;
65 
66  /* Attributes */
67  opal_hash_table_t *w_keyhash;
68 
69  /* index in Fortran <-> C translation array */
70  int w_f_to_c_index;
71 
72  /* Error handling. This field does not have the "w_" prefix so
73  that the OMPI_ERRHDL_* macros can find it, regardless of
74  whether it's a comm, window, or file. */
75  ompi_errhandler_t *error_handler;
76  ompi_errhandler_type_t errhandler_type;
77 
78  /* displacement factor */
79  int w_disp_unit;
80 
81  void *w_baseptr;
82  size_t w_size;
83 
84  /** Current epoch / mode (access, expose, lock, etc.). Checked by
85  the argument checking code in the MPI layer, set by the OSC
86  component. Modified without locking w_lock. */
87  volatile uint16_t w_mode;
88 
89  /* one sided interface */
90  ompi_osc_base_module_t *w_osc_module;
91 };
92 typedef struct ompi_win_t ompi_win_t;
93 OMPI_DECLSPEC OBJ_CLASS_DECLARATION(ompi_win_t);
94 
95 /**
96  * Padded struct to maintain back compatibiltiy.
97  * See ompi/communicator/communicator.h comments with struct ompi_communicator_t
98  * for full explanation why we chose the following padding construct for predefines.
99  */
100 #define PREDEFINED_WIN_PAD (sizeof(void*) * 64)
101 
103  struct ompi_win_t win;
104  char padding[PREDEFINED_WIN_PAD - sizeof(ompi_win_t)];
105 };
107 
108 OMPI_DECLSPEC extern ompi_predefined_win_t ompi_mpi_win_null;
109 
110 int ompi_win_init(void);
111 int ompi_win_finalize(void);
112 
113 int ompi_win_create(void *base, size_t size, int disp_unit,
114  ompi_communicator_t *comm, ompi_info_t *info,
115  ompi_win_t **newwin);
116 
117 int ompi_win_free(ompi_win_t *win);
118 
119 OMPI_DECLSPEC int ompi_win_set_name(ompi_win_t *win, char *win_name);
120 OMPI_DECLSPEC int ompi_win_get_name(ompi_win_t *win, char *win_name, int *length);
121 
122 OMPI_DECLSPEC int ompi_win_group(ompi_win_t *win, ompi_group_t **group);
123 
124 /* Note that the defintion of an "invalid" window is closely related
125  to the defintion of an "invalid" communicator. See a big comment
126  in ompi/communicator/communicator.h about this. */
127 static inline int ompi_win_invalid(ompi_win_t *win) {
128  if (NULL == win ||
129  MPI_WIN_NULL == win ||
130  (OMPI_WIN_INVALID & win->w_flags) ||
131  (OMPI_WIN_FREED & win->w_flags)) {
132  return true;
133  } else {
134  return false;
135  }
136 }
137 
138 static inline int ompi_win_peer_invalid(ompi_win_t *win, int peer) {
139  if (win->w_group->grp_proc_count <= peer) return true;
140  return false;
141 }
142 
143 static inline int ompi_win_rank(ompi_win_t *win) {
144  return win->w_group->grp_my_rank;
145 }
146 
147 static inline bool ompi_win_allow_locks(ompi_win_t *win) {
148  return (0 == (win->w_flags & OMPI_WIN_NO_LOCKS));
149 }
150 
151 static inline int16_t ompi_win_get_mode(ompi_win_t *win) {
152  int16_t mode = win->w_mode;
153  opal_atomic_rmb();
154  return mode;
155 }
156 
157 static inline void ompi_win_set_mode(ompi_win_t *win, int16_t mode) {
158  win->w_mode = mode;
159  opal_atomic_wmb();
160 }
161 
162 static inline void ompi_win_append_mode(ompi_win_t *win, int16_t mode) {
163  win->w_mode |= mode;
164  opal_atomic_wmb();
165 }
166 
167 static inline void ompi_win_remove_mode(ompi_win_t *win,
168  int16_t mode)
169 {
170  win->w_mode &= ~mode;
171  opal_atomic_wmb();
172 }
173 
174 /* already in an access epoch */
175 static inline bool ompi_win_access_epoch(ompi_win_t *win) {
176  int16_t mode = ompi_win_get_mode(win);
177  return (0 != (OMPI_WIN_ACCESS_EPOCH & mode) ? true : false);
178 }
179 
180 /* already in an exposure epoch */
181 static inline bool ompi_win_exposure_epoch(ompi_win_t *win) {
182  int16_t mode = ompi_win_get_mode(win);
183  return (0 != (OMPI_WIN_EXPOSE_EPOCH & mode) ? true : false);
184 }
185 
186 /* we're either already in an access epoch or can easily start one
187  (stupid fence rule). Either way, it's ok to be the origin of a
188  communication call. */
189 static inline bool ompi_win_comm_allowed(ompi_win_t *win) {
190  int16_t mode = ompi_win_get_mode(win);
191  return (0 != (OMPI_WIN_ACCESS_EPOCH & mode || OMPI_WIN_FENCE & mode) ? true : false);
192 }
193 
194 END_C_DECLS
195 #endif
OSC module instance.
Definition: osc.h:269
Definition: win.h:102
Definition: opal_hash_table.h:42
Definition: win.h:53
dynamic pointer array
Definition: opal_pointer_array.h:45
void opal_atomic_rmb(void)
Read memory barrier.
Back-end type for MPI_Errorhandler.
Definition: errhandler.h:108
Definition: mutex_unix.h:53
volatile uint16_t w_mode
Current epoch / mode (access, expose, lock, etc.).
Definition: win.h:87
int grp_proc_count
number of processes in group
Definition: group.h:81
Definition: info.h:38
One-sided Communication interface.
int grp_my_rank
rank in group
Definition: group.h:82
A hash table that may be indexed with either fixed length (e.g.
Group structure Currently we have four formats for storing the process pointers that are members of t...
Definition: group.h:79
Base object.
Definition: opal_object.h:182
void opal_atomic_wmb(void)
Write memory barrier.
Infrastructure for MPI group support.
A simple C-language object-oriented system with single inheritance and ownership-based memory managem...
Definition: communicator.h:118
ompi_errhandler_type_t
Enum used to describe what kind MPI object an error handler is used for.
Definition: errhandler.h:84
#define OBJ_CLASS_DECLARATION(NAME)
Declaration for class descriptor.
Definition: opal_object.h:236