Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Caitlin Ross
codes
Commits
c7ff9d37
Commit
c7ff9d37
authored
Jul 31, 2013
by
Philip Carns
Browse files
Kevin's configuration updates from CODES repo
parent
4fbef38d
Changes
4
Hide whitespace changes
Inline
Side-by-side
codes/codes_mapping.h
View file @
c7ff9d37
...
...
@@ -12,15 +12,6 @@
#include "lp-type-lookup.h"
#define MAX_NAME_LENGTH 256
/* number of LPs assigned to the current PE (abstraction of MPI rank) */
static
int
lps_for_this_pe
=
0
;
/* data structure to hold configuration */
configuration_t
config
;
/* char arrays for holding lp type name and group name*/
char
local_grp_name
[
MAX_NAME_LENGTH
],
local_lp_name
[
MAX_NAME_LENGTH
];
/* Returns number of LPs on the current PE */
int
codes_mapping_get_lps_for_pe
(
void
);
...
...
@@ -28,7 +19,7 @@ int codes_mapping_get_lps_for_pe(void);
tw_peid
codes_mapping
(
tw_lpid
gid
);
/* loads the configuration file and sets up the number of LPs on each PE. */
void
codes_mapping_setup
(
char
*
filepath
);
void
codes_mapping_setup
(
void
);
/* Takes the group name , type name, rep ID and offset (for that lp type + repetition) and then returns the global LP ID. */
void
codes_mapping_get_lp_id
(
char
*
grp_name
,
char
*
lp_type_name
,
int
rep_id
,
int
offset
,
tw_lpid
*
gid
);
...
...
codes/configuration.h
View file @
c7ff9d37
#ifndef __CONFIGURATION_H__
#define __CONFIGURATION_H__
#include <stdint.h>
#include <stdlib.h>
#include <inttypes.h>
#include <mpi.h>
#include "codes/txt_configfile.h"
#define CONFIGURATION_MAX_NAME 256
#define CONFIGURATION_MAX_GROUPS 10
...
...
@@ -22,13 +23,121 @@ typedef struct config_lpgroup_s
uint64_t
lptypes_count
;
}
config_lpgroup_t
;
typedef
struct
config
uration
_s
typedef
struct
config
_lpgroups
_s
{
config_lpgroup_t
lpgroups
[
CONFIGURATION_MAX_GROUPS
];
uint64_t
lpgroups_count
;
}
config
uration
_t
;
}
config
_lpgroups
_t
;
int
configuration_load
(
const
char
*
filepath
,
configuration_t
*
config
);
int
configuration_dump
(
configuration_t
*
config
);
/*
* Load a configuration on the system (collectively)
*
* filepath - path and name of file
* comm - communicator to distribute file on
* handle - output of configuration
*
* return 0 on success
*/
int
configuration_load
(
const
char
*
filepath
,
MPI_Comm
comm
,
ConfigHandle
*
handle
);
/*
* Free any resources allocated on load.
*
* handle - configuration handle
*/
int
configuration_free
(
ConfigHandle
*
handle
);
/*
* Get's the value for a give section/key pair.
* Caller's responsible for transforming it to a useable type.
* Assumes the key name is a KEY configuration type.
*
* handle - configuration handle
* section_name - name of the section the key is in
* key_name - name of the key
* value - pointer to string
* length - maximum length of string
*/
int
configuration_get_value
(
ConfigHandle
*
handle
,
const
char
*
section_name
,
const
char
*
key_name
,
char
*
value
,
size_t
length
);
/*
* Get's the value for a give section/key pair and converts it to an int.
* Assumes the key name is a KEY configuration type.
*
* handle - configuration handle
* section_name - name of the section the key is in
* key_name - name of the key
* value - returned as a pointer to an integer
*/
int
configuration_get_value_int
(
ConfigHandle
*
handle
,
const
char
*
section_name
,
const
char
*
key_name
,
int
*
value
);
/*
* Get's the value for a give section/key pair and converts it to an
* unsigned int.
* Assumes the key name is a KEY configuration type.
*
* handle - configuration handle
* section_name - name of the section the key is in
* key_name - name of the key
* value - returned as a pointer to an unsigned integer
*/
int
configuration_get_value_uint
(
ConfigHandle
*
handle
,
const
char
*
section_name
,
const
char
*
key_name
,
unsigned
int
*
value
);
/*
* Get's the value for a give section/key pair and converts it to a long int.
* Assumes the key name is a KEY configuration type.
*
* handle - configuration handle
* section_name - name of the section the key is in
* key_name - name of the key
* value - returned as a pointer to a long integer
*/
int
configuration_get_value_longint
(
ConfigHandle
*
handle
,
const
char
*
section_name
,
const
char
*
key_name
,
long
int
*
value
);
/*
* Get's the value for a give section/key pair and converts it to a double.
* Assumes the key name is a KEY configuration type.
*
* handle - configuration handle
* section_name - name of the section the key is in
* key_name - name of the key
* value - returned as a pointer to a double
*/
int
configuration_get_value_double
(
ConfigHandle
*
handle
,
const
char
*
section_name
,
const
char
*
key_name
,
double
*
value
);
/*
* Get the LPGROUPS configuration from the config file which is stored
* in the associated data structures.
*
* handle - configuration handle
* section_name - name of section which has the lptypes
* lpgroups - data structure to hold the lpgroup info
*/
int
configuration_get_lpgroups
(
ConfigHandle
*
handle
,
const
char
*
section_name
,
config_lpgroups_t
*
lpgroups
);
/*
* Forward reference to the configuration handle
*/
extern
ConfigHandle
config
;
#endif
src/util/codes_mapping.c
View file @
c7ff9d37
...
...
@@ -9,6 +9,14 @@
*/
#include "codes/codes_mapping.h"
/* number of LPs assigned to the current PE (abstraction of MPI rank) */
static
int
lps_for_this_pe
=
0
;
/* char arrays for holding lp type name and group name*/
char
local_grp_name
[
MAX_NAME_LENGTH
],
local_lp_name
[
MAX_NAME_LENGTH
];
config_lpgroups_t
lpconf
;
int
codes_mapping_get_lps_for_pe
()
{
return
lps_for_this_pe
;
...
...
@@ -21,21 +29,20 @@ tw_peid codes_mapping( tw_lpid gid)
}
/* This function loads the configuration file and sets up the number of LPs on each PE */
void
codes_mapping_setup
(
char
*
filepath
)
void
codes_mapping_setup
()
{
/* TODO: Add full file path? This one only runs from current directory */
configuration_load
(
filepath
,
&
config
);
configuration_dump
(
&
config
);
int
grp
,
lpt
;
int
pes
=
tw_nnodes
();
for
(
grp
=
0
;
grp
<
config
.
lpgroups_count
;
grp
++
)
configuration_get_lpgroups
(
&
config
,
"LPGROUPS"
,
&
lpconf
);
for
(
grp
=
0
;
grp
<
lpconf
.
lpgroups_count
;
grp
++
)
{
for
(
lpt
=
0
;
lpt
<
conf
ig
.
lpgroups
[
grp
].
lptypes_count
;
lpt
++
)
lps_for_this_pe
+=
(
conf
ig
.
lpgroups
[
grp
].
lptypes
[
lpt
].
count
*
conf
ig
.
lpgroups
[
grp
].
repetitions
);
for
(
lpt
=
0
;
lpt
<
lp
conf
.
lpgroups
[
grp
].
lptypes_count
;
lpt
++
)
lps_for_this_pe
+=
(
lp
conf
.
lpgroups
[
grp
].
lptypes
[
lpt
].
count
*
lp
conf
.
lpgroups
[
grp
].
repetitions
);
}
lps_for_this_pe
/=
pes
;
//printf("\n LPs for this PE are %d reps %d ", lps_for_this_pe, conf
ig
.lpgroups[grp].repetitions);
//printf("\n LPs for this PE are %d reps %d ", lps_for_this_pe,
lp
conf.lpgroups[grp].repetitions);
}
/* This function takes the group ID , type ID and rep ID then returns the global LP ID */
...
...
@@ -46,32 +53,32 @@ void codes_mapping_get_lp_id(char* grp_name, char* lp_type_name, int rep_id, int
short
found
=
0
;
// Account for all lps in the previous groups
for
(
grp
=
0
;
grp
<
conf
ig
.
lpgroups_count
;
grp
++
)
for
(
grp
=
0
;
grp
<
lp
conf
.
lpgroups_count
;
grp
++
)
{
lp_types_count
=
conf
ig
.
lpgroups
[
grp
].
lptypes_count
;
rep
=
conf
ig
.
lpgroups
[
grp
].
repetitions
;
lp_types_count
=
lp
conf
.
lpgroups
[
grp
].
lptypes_count
;
rep
=
lp
conf
.
lpgroups
[
grp
].
repetitions
;
if
(
strcmp
(
conf
ig
.
lpgroups
[
grp
].
name
,
grp_name
)
==
0
)
if
(
strcmp
(
lp
conf
.
lpgroups
[
grp
].
name
,
grp_name
)
==
0
)
{
found
=
1
;
break
;
}
for
(
lpt
=
0
;
lpt
<
lp_types_count
;
lpt
++
)
lpcount
+=
(
rep
*
conf
ig
.
lpgroups
[
grp
].
lptypes
[
lpt
].
count
);
lpcount
+=
(
rep
*
lp
conf
.
lpgroups
[
grp
].
lptypes
[
lpt
].
count
);
}
assert
(
found
);
found
=
0
;
lp_types_count
=
conf
ig
.
lpgroups
[
grp
].
lptypes_count
;
lp_types_count
=
lp
conf
.
lpgroups
[
grp
].
lptypes_count
;
// Account for the previous lp types in the current repetition
for
(
lpt
=
0
;
lpt
<
lp_types_count
;
lpt
++
)
{
count_for_this_lpt
=
conf
ig
.
lpgroups
[
grp
].
lptypes
[
lpt
].
count
;
count_for_this_lpt
=
lp
conf
.
lpgroups
[
grp
].
lptypes
[
lpt
].
count
;
if
(
strcmp
(
conf
ig
.
lpgroups
[
grp
].
lptypes
[
lpt
].
name
,
lp_type_name
)
==
0
)
if
(
strcmp
(
lp
conf
.
lpgroups
[
grp
].
lptypes
[
lpt
].
name
,
lp_type_name
)
==
0
)
{
found
=
1
;
break
;
...
...
@@ -85,7 +92,7 @@ void codes_mapping_get_lp_id(char* grp_name, char* lp_type_name, int rep_id, int
for
(
rep
=
0
;
rep
<
rep_id
;
rep
++
)
{
for
(
lpt
=
0
;
lpt
<
lp_types_count
;
lpt
++
)
lpcount
+=
conf
ig
.
lpgroups
[
grp
].
lptypes
[
lpt
].
count
;
lpcount
+=
lp
conf
.
lpgroups
[
grp
].
lptypes
[
lpt
].
count
;
}
*
gid
=
lpcount
+
offset
;
}
...
...
@@ -99,16 +106,16 @@ void codes_mapping_get_lp_info(tw_lpid gid, char* grp_name, int* grp_id, int* lp
short
found
=
0
;
/* Find the group id first */
for
(
grp
=
0
;
grp
<
conf
ig
.
lpgroups_count
;
grp
++
)
for
(
grp
=
0
;
grp
<
lp
conf
.
lpgroups_count
;
grp
++
)
{
grp_offset
=
0
;
rep_offset
=
0
;
rep
=
conf
ig
.
lpgroups
[
grp
].
repetitions
;
lp_types_count
=
conf
ig
.
lpgroups
[
grp
].
lptypes_count
;
rep
=
lp
conf
.
lpgroups
[
grp
].
repetitions
;
lp_types_count
=
lp
conf
.
lpgroups
[
grp
].
lptypes_count
;
for
(
lpt
=
0
;
lpt
<
lp_types_count
;
lpt
++
)
{
lp_count
=
conf
ig
.
lpgroups
[
grp
].
lptypes
[
lpt
].
count
;
lp_count
=
lp
conf
.
lpgroups
[
grp
].
lptypes
[
lpt
].
count
;
grp_offset
+=
(
rep
*
lp_count
);
rep_offset
+=
lp_count
;
}
...
...
@@ -117,7 +124,7 @@ void codes_mapping_get_lp_info(tw_lpid gid, char* grp_name, int* grp_id, int* lp
if
(
gid
>=
grp_lp_count
&&
gid
<
grp_lp_count
+
grp_offset
)
{
*
grp_id
=
grp
;
strcpy
(
local_grp_name
,
conf
ig
.
lpgroups
[
grp
].
name
);
strcpy
(
local_grp_name
,
lp
conf
.
lpgroups
[
grp
].
name
);
lp_offset
=
gid
-
grp_lp_count
;
/* gets the lp offset starting from the point where the group begins */
*
grp_rep_id
=
lp_offset
/
rep_offset
;
lp_tmp_id
=
lp_offset
-
(
*
grp_rep_id
*
rep_offset
);
...
...
@@ -133,11 +140,11 @@ void codes_mapping_get_lp_info(tw_lpid gid, char* grp_name, int* grp_id, int* lp
/* Now we compute the LP type ID here based on the lp offset that we just got */
for
(
lpt
=
0
;
lpt
<
lp_types_count
;
lpt
++
)
{
lp_count
=
conf
ig
.
lpgroups
[
grp
].
lptypes
[
lpt
].
count
;
lp_count
=
lp
conf
.
lpgroups
[
grp
].
lptypes
[
lpt
].
count
;
if
(
lp_tmp_id
>=
lp_offset
&&
lp_tmp_id
<
lp_offset
+
lp_count
)
{
*
lp_type_id
=
lpt
;
strcpy
(
local_lp_name
,
conf
ig
.
lpgroups
[
grp
].
lptypes
[
lpt
].
name
);
strcpy
(
local_lp_name
,
lp
conf
.
lpgroups
[
grp
].
lptypes
[
lpt
].
name
);
*
offset
=
lp_tmp_id
-
lp_offset
;
found
=
1
;
break
;
...
...
src/util/configuration.c
View file @
c7ff9d37
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include "codes/configuration.h"
#include "codes/txt_configfile.h"
int
configuration_load
(
const
char
*
filepath
,
configuration_t
*
config
)
/*
* Global to hold configuration in memory
*/
ConfigHandle
config
;
int
configuration_load
(
const
char
*
filepath
,
MPI_Comm
comm
,
ConfigHandle
*
handle
)
{
MPI_File
fh
;
MPI_Status
status
;
MPI_Offset
txtsize
;
FILE
*
f
;
char
*
txtdata
;
char
*
error
;
int
rc
;
rc
=
MPI_File_open
(
comm
,
(
char
*
)
filepath
,
MPI_MODE_RDONLY
,
MPI_INFO_NULL
,
&
fh
);
assert
(
rc
==
MPI_SUCCESS
);
rc
=
MPI_File_get_size
(
fh
,
&
txtsize
);
assert
(
rc
==
MPI_SUCCESS
);
txtdata
=
malloc
(
txtsize
);
assert
(
txtdata
);
rc
=
MPI_File_read_all
(
fh
,
txtdata
,
txtsize
,
MPI_BYTE
,
&
status
);
assert
(
rc
==
MPI_SUCCESS
);
rc
=
MPI_File_close
(
&
fh
);
assert
(
rc
==
MPI_SUCCESS
);
f
=
fmemopen
(
txtdata
,
txtsize
,
"rb"
);
assert
(
f
);
*
handle
=
txtfile_openStream
(
f
,
&
error
);
if
(
error
)
{
fprintf
(
stderr
,
"config error: %s
\n
"
,
error
);
free
(
error
);
rc
=
1
;
}
else
{
rc
=
0
;
}
fclose
(
f
);
return
rc
;
}
int
configuration_get_value
(
ConfigHandle
*
handle
,
const
char
*
section_name
,
const
char
*
key_name
,
char
*
value
,
size_t
len
)
{
SectionHandle
section_handle
;
int
rc
;
rc
=
cf_openSection
(
*
handle
,
ROOT_SECTION
,
section_name
,
&
section_handle
);
assert
(
rc
==
1
);
rc
=
cf_getKey
(
*
handle
,
section_handle
,
key_name
,
value
,
len
);
assert
(
rc
);
(
void
)
cf_closeSection
(
*
handle
,
section_handle
);
return
rc
;
}
int
configuration_get_value_int
(
ConfigHandle
*
handle
,
const
char
*
section_name
,
const
char
*
key_name
,
int
*
value
)
{
char
valuestr
[
256
];
int
rc
=
1
;
int
r
;
r
=
configuration_get_value
(
handle
,
section_name
,
key_name
,
valuestr
,
sizeof
(
valuestr
));
if
(
r
>
0
)
{
*
value
=
atoi
(
valuestr
);
rc
=
0
;
}
return
rc
;
}
int
configuration_get_value_uint
(
ConfigHandle
*
handle
,
const
char
*
section_name
,
const
char
*
key_name
,
unsigned
int
*
value
)
{
char
valuestr
[
256
];
int
rc
=
1
;
int
r
;
r
=
configuration_get_value
(
handle
,
section_name
,
key_name
,
valuestr
,
sizeof
(
valuestr
));
if
(
r
>
0
)
{
*
value
=
(
unsigned
int
)
atoi
(
valuestr
);
rc
=
0
;
}
return
rc
;
}
int
configuration_get_value_longint
(
ConfigHandle
*
handle
,
const
char
*
section_name
,
const
char
*
key_name
,
long
int
*
value
)
{
char
valuestr
[
256
];
int
rc
=
1
;
int
r
;
r
=
configuration_get_value
(
handle
,
section_name
,
key_name
,
valuestr
,
sizeof
(
valuestr
));
if
(
r
>
0
)
{
errno
=
0
;
*
value
=
strtol
(
valuestr
,
NULL
,
10
);
rc
=
errno
;
}
return
rc
;
}
int
configuration_get_value_double
(
ConfigHandle
*
handle
,
const
char
*
section_name
,
const
char
*
key_name
,
double
*
value
)
{
char
valuestr
[
256
];
int
rc
=
1
;
int
r
;
r
=
configuration_get_value
(
handle
,
section_name
,
key_name
,
valuestr
,
sizeof
(
valuestr
));
if
(
r
>
0
)
{
errno
=
0
;
*
value
=
strtod
(
valuestr
,
NULL
);
rc
=
errno
;
}
return
rc
;
}
int
configuration_get_lpgroups
(
ConfigHandle
*
handle
,
const
char
*
section_name
,
config_lpgroups_t
*
lpgroups
)
{
char
*
errstr
;
ConfigHandle
ch
;
SectionHandle
sh
;
SectionHandle
subsh
;
SectionEntry
se
[
10
];
...
...
@@ -15,74 +184,51 @@ int configuration_load (const char *filepath, configuration_t *config)
int
i
,
j
,
lpt
;
char
data
[
256
];
memset
(
config
,
0
,
sizeof
(
*
config
));
errstr
=
NULL
;
memset
(
lpgroups
,
0
,
sizeof
(
*
lpgroups
));
ch
=
txtfile_openConfig
(
filepath
,
&
errstr
);
cf_openSection
(
ch
,
ROOT_SECTION
,
"LPGROUPS"
,
&
sh
);
cf_listSection
(
ch
,
sh
,
se
,
&
se_count
);
cf_openSection
(
*
handle
,
ROOT_SECTION
,
section_name
,
&
sh
);
cf_listSection
(
*
handle
,
sh
,
se
,
&
se_count
);
for
(
i
=
0
;
i
<
se_count
;
i
++
)
{
printf
(
"section: %s type: %d
\n
"
,
se
[
i
].
name
,
se
[
i
].
type
);
//
printf("section: %s type: %d\n", se[i].name, se[i].type);
if
(
se
[
i
].
type
==
SE_SECTION
)
{
subse_count
=
10
;
cf_openSection
(
ch
,
sh
,
se
[
i
].
name
,
&
subsh
);
cf_listSection
(
ch
,
subsh
,
subse
,
&
subse_count
);
strncpy
(
config
->
lpgroups
[
i
].
name
,
se
[
i
].
name
,
cf_openSection
(
*
handle
,
sh
,
se
[
i
].
name
,
&
subsh
);
cf_listSection
(
*
handle
,
subsh
,
subse
,
&
subse_count
);
strncpy
(
lpgroups
->
lpgroups
[
i
].
name
,
se
[
i
].
name
,
CONFIGURATION_MAX_NAME
);
config
->
lpgroups
[
i
].
repetitions
=
1
;
config
->
lpgroups_count
++
;
lpgroups
->
lpgroups
[
i
].
repetitions
=
1
;
lpgroups
->
lpgroups_count
++
;
for
(
j
=
0
,
lpt
=
0
;
j
<
subse_count
;
j
++
)
{
if
(
subse
[
j
].
type
==
SE_KEY
)
{
cf_getKey
(
ch
,
subsh
,
subse
[
j
].
name
,
data
,
sizeof
(
data
));
printf
(
"key: %s value: %s
\n
"
,
subse
[
j
].
name
,
data
);
cf_getKey
(
*
handle
,
subsh
,
subse
[
j
].
name
,
data
,
sizeof
(
data
));
//
printf("key: %s value: %s\n", subse[j].name, data);
if
(
strcmp
(
"repetitions"
,
subse
[
j
].
name
)
==
0
)
{
config
->
lpgroups
[
i
].
repetitions
=
atoi
(
data
);
//
printf("\n Repetitions: %d ",
config
->lpgroups[i].repetitions);
lpgroups
->
lpgroups
[
i
].
repetitions
=
atoi
(
data
);
//
printf("\n Repetitions: %
l
d ",
lpgroups
->lpgroups[i].repetitions);
}
else
{
// assume these are lptypes and counts
strncpy
(
config
->
lpgroups
[
i
].
lptypes
[
lpt
].
name
,
strncpy
(
lpgroups
->
lpgroups
[
i
].
lptypes
[
lpt
].
name
,
subse
[
j
].
name
,
sizeof
(
config
->
lpgroups
[
i
].
lptypes
[
lpt
].
name
));
config
->
lpgroups
[
i
].
lptypes
[
lpt
].
count
=
atoi
(
data
);
config
->
lpgroups
[
i
].
lptypes_count
++
;
sizeof
(
lpgroups
->
lpgroups
[
i
].
lptypes
[
lpt
].
name
));
lpgroups
->
lpgroups
[
i
].
lptypes
[
lpt
].
count
=
atoi
(
data
);
lpgroups
->
lpgroups
[
i
].
lptypes_count
++
;
lpt
++
;
}
}
}
cf_closeSection
(
ch
,
subsh
);
cf_closeSection
(
*
handle
,
subsh
);
}
}
cf_closeSection
(
ch
,
sh
);
cf_closeSection
(
*
handle
,
sh
);
if
(
errstr
)
free
(
errstr
);
return
0
;
}
int
configuration_dump
(
configuration_t
*
config
)
{
int
grp
;
int
lpt
;
for
(
grp
=
0
;
grp
<
config
->
lpgroups_count
;
grp
++
)
{
printf
(
"group: %s
\n
"
,
config
->
lpgroups
[
grp
].
name
);
printf
(
"
\t
repetitions: %d
\n
"
,
config
->
lpgroups
[
grp
].
repetitions
);
for
(
lpt
=
0
;
lpt
<
config
->
lpgroups
[
grp
].
lptypes_count
;
lpt
++
)
{
printf
(
"
\t
%s: %ld
\n
"
,
config
->
lpgroups
[
grp
].
lptypes
[
lpt
].
name
,
config
->
lpgroups
[
grp
].
lptypes
[
lpt
].
count
);
}
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment