Yet Another eXchange Tool  0.9.0
xt_config.c
Go to the documentation of this file.
1 
13 /*
14  * Maintainer: Jörg Behrens <behrens@dkrz.de>
15  * Moritz Hanke <hanke@dkrz.de>
16  * Thomas Jahns <jahns@dkrz.de>
17  *
18  * URL: https://doc.redmine.dkrz.de/yaxt/html/
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions are
22  * met:
23  *
24  * Redistributions of source code must retain the above copyright notice,
25  * this list of conditions and the following disclaimer.
26  *
27  * Redistributions in binary form must reproduce the above copyright
28  * notice, this list of conditions and the following disclaimer in the
29  * documentation and/or other materials provided with the distribution.
30  *
31  * Neither the name of the DKRZ GmbH nor the names of its contributors
32  * may be used to endorse or promote products derived from this software
33  * without specific prior written permission.
34  *
35  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
36  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
37  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
38  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
39  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
40  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
41  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
42  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
43  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
44  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
45  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46  */
47 #ifdef HAVE_CONFIG_H
48 #include <config.h>
49 #endif
50 
51 #include <string.h>
52 
53 #include <mpi.h>
54 
55 #include <xt/xt_config.h>
56 #include "xt_config_internal.h"
62 #include "core/core.h"
63 #include "core/ppm_xfuncs.h"
64 
67 };
68 
70 {
71  Xt_config config = xmalloc(sizeof(*config));
72  *config = xt_default_config;
73  return config;
74 }
75 
77 {
78  free(config);
79 }
80 
81 static const struct {
82  char name[20];
84  int code;
85 } exchanger_table[] = {
86  { "irecv_send",
88  { "irecv_isend",
90  { "irecv_isend_packed",
92  { "mix_irecv_isend",
94  { "neigh_alltoall",
96 };
97 
98 enum {
99  num_exchanger = sizeof (exchanger_table) / sizeof (exchanger_table[0]),
100 };
101 
102 int
104 {
105  for (size_t i = 0; i < num_exchanger; ++i)
106  if (!strcmp(name, exchanger_table[i].name))
107  return exchanger_table[i].code;
108  return -1;
109 }
110 
112 {
113  Xt_exchanger_new exchanger_new = config->exchanger_new;
114  for (size_t i = 0; i < num_exchanger; ++i)
115  if (exchanger_table[i].f == exchanger_new)
116  return (int)i;
117  static const char fmt[]
118  = "error: unexpected exchanger function (%p)!\n";
119  char buf[sizeof (fmt) + 9];
120  sprintf(buf, fmt, (void *)exchanger_new);
121  Xt_abort(Xt_default_comm, buf, "xt_config.c", __LINE__);
122 }
123 
124 
125 void xt_config_set_exchange_method(Xt_config config, int method)
126 {
127  for (size_t i = 0; i < num_exchanger; ++i)
128  if (exchanger_table[i].code == method) {
129  config->exchanger_new = exchanger_table[i].f;
130  return;
131  }
132  static const char fmt[]
133  = "error: user-requested exchanger code (%d) does not exist!\n";
134  char buf[sizeof (fmt) + 9];
135  sprintf(buf, fmt, method);
136  Xt_abort(Xt_default_comm, buf, "xt_config.c", __LINE__);
137 }
138 
139 void
141 {
142  const char *config_env = getenv("XT_CONFIG_DEFAULT_EXCHANGE_METHOD");
143  if (config_env) {
144  int exchanger_id = xt_exchanger_id_by_name(config_env);
145  if (exchanger_id != -1)
147  }
148 }
149 
150 /*
151  * Local Variables:
152  * c-basic-offset: 2
153  * coding: utf-8
154  * indent-tabs-mode: nil
155  * show-trailing-whitespace: t
156  * require-trailing-newline: t
157  * End:
158  */
add versions of standard API functions not returning on error
#define xmalloc(size)
Definition: ppm_xfuncs.h:70
Xt_exchanger_new exchanger_new
void xt_config_defaults_init(void)
Definition: xt_config.c:140
static const struct @3 exchanger_table[]
int xt_exchanger_id_by_name(const char *name)
Definition: xt_config.c:103
void xt_config_delete(Xt_config config)
Definition: xt_config.c:76
void xt_config_set_exchange_method(Xt_config config, int method)
Definition: xt_config.c:125
int code
Definition: xt_config.c:84
Xt_config xt_config_new(void)
Definition: xt_config.c:69
char name[20]
Definition: xt_config.c:82
int xt_config_get_exchange_method(Xt_config config)
Definition: xt_config.c:111
struct Xt_config_ xt_default_config
Definition: xt_config.c:65
@ num_exchanger
Definition: xt_config.c:99
Xt_exchanger_new f
Definition: xt_config.c:83
opaque configuration object for settings where the default needs to be overridden
@ xt_exchanger_irecv_isend
Definition: xt_config.h:75
@ xt_exchanger_irecv_send
Definition: xt_config.h:74
@ xt_exchanger_irecv_isend_packed
Definition: xt_config.h:76
@ xt_exchanger_neigh_alltoall
Definition: xt_config.h:78
@ xt_exchanger_mix_isend_irecv
Definition: xt_config.h:77
implementation of configuration object
Xt_exchanger(* Xt_exchanger_new)(int nsend, int nrecv, const struct Xt_redist_msg *send_msgs, const struct Xt_redist_msg *recv_msgs, MPI_Comm comm, int tag_offset)
Definition: xt_exchanger.h:155
Xt_exchanger xt_exchanger_irecv_isend_new(int nsend, int nrecv, const struct Xt_redist_msg *send_msgs, const struct Xt_redist_msg *recv_msgs, MPI_Comm comm, int tag_offset)
Xt_exchanger xt_exchanger_irecv_isend_packed_new(int nsend, int nrecv, const struct Xt_redist_msg *send_msgs, const struct Xt_redist_msg *recv_msgs, MPI_Comm comm, int tag_offset)
Xt_exchanger xt_exchanger_irecv_send_new(int nsend, int nrecv, const struct Xt_redist_msg *send_msgs, const struct Xt_redist_msg *recv_msgs, MPI_Comm comm, int tag_offset)
Xt_exchanger xt_exchanger_mix_isend_irecv_new(int nsend, int nrecv, const struct Xt_redist_msg *send_msgs, const struct Xt_redist_msg *recv_msgs, MPI_Comm comm, int tag_offset)
Xt_exchanger xt_exchanger_neigh_alltoall_new(int nsend, int nrecv, const struct Xt_redist_msg *send_msgs, const struct Xt_redist_msg *recv_msgs, MPI_Comm comm, int tag_offset)