OpenMPI  0.1.1
base.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3  * University Research and Technology
4  * Corporation. All rights reserved.
5  * Copyright (c) 2004-2011 The University of Tennessee and The University
6  * of Tennessee Research Foundation. All rights
7  * reserved.
8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9  * University of Stuttgart. All rights reserved.
10  * Copyright (c) 2004-2005 The Regents of the University of California.
11  * All rights reserved.
12  * Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
13  * $COPYRIGHT$
14  *
15  * Additional copyrights may follow
16  *
17  * $HEADER$
18  */
19 /**
20  * @file
21  *
22  * I/O Forwarding Service
23  */
24 
25 #ifndef MCA_IOF_BASE_H
26 #define MCA_IOF_BASE_H
27 
28 #include "orte_config.h"
29 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
31 #endif
32 #ifdef HAVE_SYS_UIO_H
33 #include <sys/uio.h>
34 #endif
35 #ifdef HAVE_NET_UIO_H
36 #include <net/uio.h>
37 #endif
38 #ifdef HAVE_UNISTD_H
39 #include <unistd.h>
40 #endif
41 #ifdef HAVE_SIGNAL_H
42 #include <signal.h>
43 #endif
44 
45 #include "opal/mca/mca.h"
46 
47 #include "orte/mca/iof/iof.h"
49 
50 BEGIN_C_DECLS
51 
52 ORTE_DECLSPEC int orte_iof_base_open(void);
53 
54 #if !ORTE_DISABLE_FULL_SUPPORT
55 
56 /*
57  * Maximum size of single msg
58  */
59 #define ORTE_IOF_BASE_MSG_MAX 4096
60 #define ORTE_IOF_BASE_TAG_MAX 50
61 #define ORTE_IOF_BASE_TAGGED_OUT_MAX 8192
62 #define ORTE_IOF_MAX_INPUT_BUFFERS 50
63 
64 typedef struct {
65  opal_list_item_t super;
66  bool pending;
67  opal_event_t ev;
68  int fd;
69  opal_list_t outputs;
72 
73 typedef struct {
74  opal_list_item_t super;
76  orte_process_name_t daemon;
77  orte_iof_tag_t tag;
79 #if OPAL_ENABLE_DEBUG
80  char *file;
81  int line;
82 #endif
85 
86 typedef struct {
87  opal_object_t super;
89  opal_event_t ev;
90  int fd;
91  orte_iof_tag_t tag;
92  bool active;
93 #if OPAL_ENABLE_DEBUG
94  char *file;
95  int line;
96 #endif
99 
100 typedef struct {
101  opal_list_item_t super;
102  orte_process_name_t name;
103  orte_iof_read_event_t *revstdout;
104  orte_iof_read_event_t *revstderr;
105  orte_iof_read_event_t *revstddiag;
108 
109 typedef struct {
110  opal_list_item_t super;
111  char data[ORTE_IOF_BASE_TAGGED_OUT_MAX];
112  int numbytes;
115 
116 /* the iof globals struct */
118  int iof_output;
119  opal_list_t iof_components_opened;
120  opal_mutex_t iof_write_output_lock;
121  orte_iof_sink_t *iof_write_stdout;
122  orte_iof_sink_t *iof_write_stderr;
123 };
124 typedef struct orte_iof_base_t orte_iof_base_t;
125 
126 
127 #if OPAL_ENABLE_DEBUG
128 
129 #define ORTE_IOF_SINK_DEFINE(snk, nm, fid, tg, wrthndlr, eplist) \
130  do { \
131  orte_iof_sink_t *ep; \
132  OPAL_OUTPUT_VERBOSE((1, orte_iof_base.iof_output, \
133  "defining endpt: file %s line %d fd %d",\
134  __FILE__, __LINE__, (fid))); \
135  ep = OBJ_NEW(orte_iof_sink_t); \
136  ep->name.jobid = (nm)->jobid; \
137  ep->name.vpid = (nm)->vpid; \
138  ORTE_EPOCH_SET(ep->name.epoch,(nm)->epoch); \
139  ep->tag = (tg); \
140  if (0 <= (fid)) { \
141  ep->wev->fd = (fid); \
142  opal_event_set(opal_event_base, \
143  &(ep->wev->ev), ep->wev->fd, \
144  OPAL_EV_WRITE, \
145  wrthndlr, ep); \
146  } \
147  if (NULL != (eplist)) { \
148  opal_list_append((eplist), &ep->super); \
149  } \
150  *(snk) = ep; \
151  ep->file = strdup(__FILE__); \
152  ep->line = __LINE__; \
153  } while(0);
154 
155 /* add list of structs that has name of proc + orte_iof_tag_t - when
156  * defining a read event, search list for proc, add flag to the tag.
157  * when closing a read fd, find proc on list and zero out that flag
158  * when all flags = 0, then iof is complete - set message event to
159  * daemon processor indicating proc iof is terminated
160  */
161 #define ORTE_IOF_READ_EVENT(rv, nm, fid, tg, cbfunc, actv) \
162  do { \
163  orte_iof_read_event_t *rev; \
164  OPAL_OUTPUT_VERBOSE((1, orte_iof_base.iof_output, \
165  "%s defining read event for %s: %s %d", \
166  ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), \
167  ORTE_NAME_PRINT((nm)), \
168  __FILE__, __LINE__)); \
169  rev = OBJ_NEW(orte_iof_read_event_t); \
170  rev->name.jobid = (nm)->jobid; \
171  rev->name.vpid = (nm)->vpid; \
172  ORTE_EPOCH_SET(rev->name.epoch,(nm)->epoch); \
173  rev->tag = (tg); \
174  rev->fd = (fid); \
175  *(rv) = rev; \
176  rev->file = strdup(__FILE__); \
177  rev->line = __LINE__; \
178  opal_event_set(opal_event_base, \
179  &rev->ev, (fid), \
180  OPAL_EV_READ, \
181  (cbfunc), rev); \
182  if ((actv)) { \
183  rev->active = true; \
184  opal_event_add(&rev->ev, 0); \
185  } \
186  } while(0);
187 
188 
189 #else
190 
191 #define ORTE_IOF_SINK_DEFINE(snk, nm, fid, tg, wrthndlr, eplist) \
192  do { \
193  orte_iof_sink_t *ep; \
194  ep = OBJ_NEW(orte_iof_sink_t); \
195  ep->name.jobid = (nm)->jobid; \
196  ep->name.vpid = (nm)->vpid; \
197  ORTE_EPOCH_SET(ep->name.epoch,(nm)->epoch); \
198  ep->tag = (tg); \
199  if (0 <= (fid)) { \
200  ep->wev->fd = (fid); \
201  opal_event_set(opal_event_base, \
202  &(ep->wev->ev), ep->wev->fd, \
203  OPAL_EV_WRITE, \
204  wrthndlr, ep); \
205  } \
206  if (NULL != (eplist)) { \
207  opal_list_append((eplist), &ep->super); \
208  } \
209  *(snk) = ep; \
210  } while(0);
211 
212 #define ORTE_IOF_READ_EVENT(rv, nm, fid, tg, cbfunc, actv) \
213  do { \
214  orte_iof_read_event_t *rev; \
215  rev = OBJ_NEW(orte_iof_read_event_t); \
216  rev->name.jobid = (nm)->jobid; \
217  rev->name.vpid = (nm)->vpid; \
218  ORTE_EPOCH_SET(rev->name.epoch,(nm)->epoch); \
219  rev->tag = (tg); \
220  rev->fd = (fid); \
221  *(rv) = rev; \
222  opal_event_set(opal_event_base, \
223  &rev->ev, (fid), \
224  OPAL_EV_READ, \
225  (cbfunc), rev); \
226  if ((actv)) { \
227  rev->active = true; \
228  opal_event_add(&rev->ev, 0); \
229  } \
230  } while(0);
231 
232 #endif
233 
234 ORTE_DECLSPEC int orte_iof_base_close(void);
235 ORTE_DECLSPEC int orte_iof_base_select(void);
236 ORTE_DECLSPEC int orte_iof_base_flush(void);
237 
238 ORTE_DECLSPEC extern orte_iof_base_t orte_iof_base;
239 
240 /* base functions */
241 ORTE_DECLSPEC int orte_iof_base_write_output(orte_process_name_t *name, orte_iof_tag_t stream,
242  unsigned char *data, int numbytes,
243  orte_iof_write_event_t *channel);
244 ORTE_DECLSPEC void orte_iof_base_write_handler(int fd, short event, void *cbdata);
245 
246 #endif /* ORTE_DISABLE_FULL_SUPPORT */
247 
248 END_C_DECLS
249 
250 #endif /* MCA_IOF_BASE_H */
BEGIN_C_DECLS ORTE_DECLSPEC int orte_iof_base_open(void)
Function for finding and opening either all MCA components, or the one that was specifically requeste...
Definition: iof_base_open.c:183
Definition: base.h:73
Definition: base.h:86
Definition: types.h:146
Structure to represent a single event.
Definition: event_struct.h:87
Definition: mutex_unix.h:53
I/O Forwarding Service The I/O forwarding service (IOF) is used to connect stdin, stdout...
Top-level interface for all MCA components.
Definition: opal_list.h:98
Definition: base.h:64
ORTE_DECLSPEC OBJ_CLASS_DECLARATION(mca_oob_base_info_t)
declare the association structure as a class
Definition: base.h:109
Base object.
Definition: opal_object.h:182
Definition: opal_list.h:147
Global params for OpenRTE.
ORTE_DECLSPEC int orte_iof_base_select(void)
Call the query function on all available components to find out if they want to run.
Definition: iof_base_select.c:36
Definition: base.h:100
Definition: base.h:117