1 /*****************************************************************************\
2  **  pmix_db.h - PMIx KVS database
3  *****************************************************************************
4  *  Copyright (C) 2014-2015 Artem Polyakov. All rights reserved.
5  *  Copyright (C) 2015-2017 Mellanox Technologies. All rights reserved.
6  *  Written by Artem Polyakov <artpol84@gmail.com, artemp@mellanox.com>.
7  *
8  *  This file is part of Slurm, a resource management program.
9  *  For details, see <https://slurm.schedmd.com/>.
10  *  Please also read the included file: DISCLAIMER.
11  *
12  *  Slurm is free software; you can redistribute it and/or modify it under
13  *  the terms of the GNU General Public License as published by the Free
14  *  Software Foundation; either version 2 of the License, or (at your option)
15  *  any later version.
16  *
17  *  In addition, as a special exception, the copyright holders give permission
18  *  to link the code of portions of this program with the OpenSSL library under
19  *  certain conditions as described in each individual source file, and
20  *  distribute linked combinations including the two. You must obey the GNU
21  *  General Public License in all respects for all of the code used other than
22  *  OpenSSL. If you modify file(s) with this exception, you may extend this
23  *  exception to your version of the file(s), but you are not obligated to do
24  *  so. If you do not wish to do so, delete this exception statement from your
25  *  version.  If you delete this exception statement from all source files in
26  *  the program, then also delete it here.
27  *
28  *  Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
29  *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
30  *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
31  *  details.
32  *
33  *  You should have received a copy of the GNU General Public License along
34  *  with Slurm; if not, write to the Free Software Foundation, Inc.,
35  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
36  \*****************************************************************************/
37 
38 #ifndef PMIXP_NSPACES_H
39 #define PMIXP_NSPACES_H
40 
41 #include "pmixp_common.h"
42 #include "pmixp_info.h"
43 #include "pmixp_debug.h"
44 #include "pmixp_state.h"
45 
46 typedef struct {
47 	void *blob;
48 	int blob_sz;
49 } pmixp_blob_t;
50 
51 typedef struct {
52 #ifndef NDEBUG
53 #define PMIXP_NSPACE_MAGIC 0xCAFED00D
54 	int magic;
55 #endif
56 	char name[PMIXP_MAX_NSLEN];
57 	uint32_t nnodes; /* number of nodes in this namespace */
58 	int node_id; /* relative position of this node in this step */
59 	uint32_t ntasks; /* total number of tasks in this namespace */
60 	uint32_t *task_cnts; /* Number of tasks on each node of namespace */
61 	char *task_map_packed; /* Packed task mapping information */
62 	uint32_t *task_map; /* i'th task is located on task_map[i] node */
63 	hostlist_t hl;
64 } pmixp_namespace_t;
65 
66 typedef struct {
67 #ifndef NDEBUG
68 #define PMIXP_NSPACE_DB_MAGIC 0xCAFEBABE
69 	int magic;
70 #endif
71 	List nspaces;
72 	pmixp_namespace_t *local;
73 } pmixp_db_t;
74 
75 int pmixp_nspaces_init(void);
76 int pmixp_nspaces_finalize(void);
77 pmixp_namespace_t *pmixp_nspaces_find(const char *name);
78 pmixp_namespace_t *pmixp_nspaces_local(void);
79 int pmixp_nspaces_add(char *name, uint32_t nnodes, int node_id,
80 		      uint32_t ntasks, uint32_t *task_cnts,
81 		      char *task_map_packed, hostlist_t hl);
82 
83 /* operations on the specific namespace */
pmixp_nspace_hostlist(pmixp_namespace_t * nsptr)84 static inline hostlist_t pmixp_nspace_hostlist(pmixp_namespace_t *nsptr)
85 {
86 	hostlist_t hl = hostlist_copy(nsptr->hl);
87 	return hl;
88 }
89 
90 hostlist_t pmixp_nspace_rankhosts(pmixp_namespace_t *nsptr,
91 				  const uint32_t *ranks, size_t nranks);
92 int pmixp_nspace_resolve(const char *name, int rank);
93 
94 size_t pmixp_nspace_mdx_lsize(List l);
95 int pmixp_nspaces_push(Buf buf, int cnt);
96 
97 #endif /* PMIXP_NSPACES_H */
98