~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to src/base/cs_syr3_comm.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-24 00:00:08 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20111124000008-2vo99e38267942q5
Tags: 2.1.0-3
Install a missing file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __CS_SYR3_COMM_H__
 
2
#define __CS_SYR3_COMM_H__
 
3
 
 
4
/*============================================================================
 
5
 * Communication with SYRTHES 3
 
6
 *============================================================================*/
 
7
 
 
8
/*
 
9
  This file is part of Code_Saturne, a general-purpose CFD tool.
 
10
 
 
11
  Copyright (C) 1998-2011 EDF S.A.
 
12
 
 
13
  This program is free software; you can redistribute it and/or modify it under
 
14
  the terms of the GNU General Public License as published by the Free Software
 
15
  Foundation; either version 2 of the License, or (at your option) any later
 
16
  version.
 
17
 
 
18
  This program is distributed in the hope that it will be useful, but WITHOUT
 
19
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
20
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
21
  details.
 
22
 
 
23
  You should have received a copy of the GNU General Public License along with
 
24
  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
25
  Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
26
*/
 
27
 
 
28
/*----------------------------------------------------------------------------*/
 
29
 
 
30
/*----------------------------------------------------------------------------
 
31
 *  Local headers
 
32
 *----------------------------------------------------------------------------*/
 
33
 
 
34
#include "cs_base.h"
 
35
 
 
36
/*----------------------------------------------------------------------------*/
 
37
 
 
38
BEGIN_C_DECLS
 
39
 
 
40
/*============================================================================
 
41
 * Macro definitions
 
42
 *============================================================================*/
 
43
 
 
44
#define CS_SYR3_COMM_FIN_FICHIER                           "EOF"
 
45
 
 
46
#define CS_SYR3_COMM_H_LEN       32   /* Length of a header name */
 
47
 
 
48
/* Socket communications: we suppose a maximum of 8 coupled SYRTHES instances;
 
49
   this value may be modified through the CS_SYR3_COMM_SOCKET_NBR_MAX
 
50
   environment variable */
 
51
 
 
52
/*============================================================================
 
53
 * Type definitions
 
54
 *============================================================================*/
 
55
 
 
56
/*----------------------------------------------------------------------------
 
57
 * Message type
 
58
 *----------------------------------------------------------------------------*/
 
59
 
 
60
typedef enum {
 
61
 
 
62
  CS_SYR3_COMM_TYPE_NONE,     /* No communication (pre-initialization) */
 
63
  CS_SYR3_COMM_TYPE_MPI,      /* MPI messages */
 
64
  CS_SYR3_COMM_TYPE_SOCKET    /* IP sockets */
 
65
 
 
66
} cs_syr3_comm_type_t;
 
67
 
 
68
/* Pointer associated with an opaque communicator structure. */
 
69
 
 
70
typedef struct _cs_syr3_comm_t cs_syr3_comm_t;
 
71
 
 
72
/* Structure used to save message header data, to simplify its use. */
 
73
 
 
74
typedef struct {
 
75
 
 
76
  char       sec_name[CS_SYR3_COMM_H_LEN + 1];
 
77
  cs_int_t   n_elts;
 
78
  cs_type_t  elt_type;
 
79
 
 
80
} cs_syr3_comm_msg_header_t;
 
81
 
 
82
/*============================================================================
 
83
 *  Global variables
 
84
 *============================================================================*/
 
85
 
 
86
/*=============================================================================
 
87
 * Public function prototypes
 
88
 *============================================================================*/
 
89
 
 
90
/*----------------------------------------------------------------------------
 
91
 * Initialize a communication
 
92
 *
 
93
 * parameters:
 
94
 *   number,       <-- coupling number
 
95
 *   proc_rank,    <-- communicating process rank (< 0 if using sockets)
 
96
 *   type,         <-- communication type
 
97
 *   echo          <-- echo on main output (< 0 if none, header if 0,
 
98
 *                     n first and last elements if n)
 
99
 *
 
100
 * returns:
 
101
 *   pointer to communication structure
 
102
 *----------------------------------------------------------------------------*/
 
103
 
 
104
cs_syr3_comm_t *
 
105
cs_syr3_comm_initialize(int                  number,
 
106
#if defined(HAVE_MPI)
 
107
                        int                  proc_rank,
 
108
#endif
 
109
                        cs_syr3_comm_type_t  type,
 
110
                        cs_int_t             echo);
 
111
 
 
112
/*----------------------------------------------------------------------------
 
113
 * Finalize a communication
 
114
 *----------------------------------------------------------------------------*/
 
115
 
 
116
cs_syr3_comm_t *
 
117
cs_syr3_comm_finalize(cs_syr3_comm_t *comm);
 
118
 
 
119
/*----------------------------------------------------------------------------
 
120
 * Return a pointer to a communicator name
 
121
 *
 
122
 * parameters:
 
123
 *   comm <-- communicator
 
124
 *
 
125
 * returns:
 
126
 *   pointer to communicator name
 
127
 *----------------------------------------------------------------------------*/
 
128
 
 
129
const char *
 
130
cs_syr3_comm_get_name(const cs_syr3_comm_t  *comm);
 
131
 
 
132
/*----------------------------------------------------------------------------
 
133
 * Send message
 
134
 *
 
135
 * parameters:
 
136
 *   nom_rub  <-- section name
 
137
 *   n_elts   <-- number of elements
 
138
 *   elt_type <-- element type if n_elts > 0
 
139
 *   elts     <-- elements if n_elts > 0
 
140
 *   comm     <-- communicator
 
141
 *----------------------------------------------------------------------------*/
 
142
 
 
143
void
 
144
cs_syr3_comm_send_message(const char             nom_rub[CS_SYR3_COMM_H_LEN],
 
145
                          cs_int_t               n_elts,
 
146
                          cs_type_t              elt_type,
 
147
                          void                  *elts,
 
148
                          const cs_syr3_comm_t  *comm);
 
149
 
 
150
/*----------------------------------------------------------------------------
 
151
 * Receive message header
 
152
 *
 
153
 * parameters:
 
154
 *   header --> message header
 
155
 *   comm   <-- communicator
 
156
 *
 
157
 * returns
 
158
 *   number of elements in message body
 
159
 *----------------------------------------------------------------------------*/
 
160
 
 
161
cs_int_t
 
162
cs_syr3_comm_receive_header(cs_syr3_comm_msg_header_t  *header,
 
163
                            const cs_syr3_comm_t       *comm);
 
164
 
 
165
/*----------------------------------------------------------------------------
 
166
 * Receive a message body
 
167
 *
 
168
 * parameters:
 
169
 *   header <-- message header
 
170
 *   elt    --> received body values
 
171
 *   comm   <-- communicator
 
172
 *----------------------------------------------------------------------------*/
 
173
 
 
174
void
 
175
cs_syr3_comm_receive_body(const cs_syr3_comm_msg_header_t  *header,
 
176
                          void                             *elt,
 
177
                          const cs_syr3_comm_t             *comm);
 
178
 
 
179
#if defined(HAVE_SOCKET)
 
180
 
 
181
/*----------------------------------------------------------------------------
 
182
 * Open an IP socket to prepare for this communication mode
 
183
 *
 
184
 * parameters:
 
185
 *   port_num <-- port number (only used for rank 0; automatic on others)
 
186
 *----------------------------------------------------------------------------*/
 
187
 
 
188
void
 
189
cs_syr3_comm_init_socket(int port_num);
 
190
 
 
191
/*----------------------------------------------------------------------------
 
192
 * Close an IP socket associated with this communication mode
 
193
 *----------------------------------------------------------------------------*/
 
194
 
 
195
void
 
196
cs_syr3_comm_finalize_socket(void);
 
197
 
 
198
#endif /* HAVE_SOCKET */
 
199
 
 
200
/*----------------------------------------------------------------------------*/
 
201
 
 
202
END_C_DECLS
 
203
 
 
204
#endif /* __CS_SYR3_COMM_H__ */