Correct a comment in paffinity.h about what paffinity_get returns - it was inaccurate.
Revamp the affinity detection/set procedure in mpi_init to correctly detect when we have already been bound to processors, given the revised understanding of paffinity_get. Add a new paffinity macro to make checking for already bound a little nicer. This commit was SVN r21402.
Этот коммит содержится в:
родитель
f9a510fd8a
Коммит
c3c1ab1337
@ -55,6 +55,9 @@
|
||||
#include "orte/util/show_help.h"
|
||||
#include "orte/mca/ess/ess.h"
|
||||
|
||||
#include "orte/mca/errmgr/errmgr.h"
|
||||
#include "orte/util/name_fns.h"
|
||||
|
||||
#include "orte/mca/notifier/notifier.h"
|
||||
|
||||
#include "ompi/constants.h"
|
||||
@ -281,6 +284,7 @@ int ompi_mpi_init(int argc, char **argv, int requested, int *provided)
|
||||
struct timeval ompistart, ompistop;
|
||||
char *event_val = NULL;
|
||||
opal_paffinity_base_cpu_set_t mask;
|
||||
bool proc_bound;
|
||||
#if 0
|
||||
/* see comment below about sched_yield */
|
||||
int num_processors;
|
||||
@ -403,47 +407,56 @@ int ompi_mpi_init(int argc, char **argv, int requested, int *provided)
|
||||
* paffinity scheme.
|
||||
*/
|
||||
ret = opal_paffinity_base_get(&mask);
|
||||
if (OPAL_ERR_NOT_FOUND == ret) {
|
||||
/* the system is capable of doing processor affinity, but it
|
||||
* has not yet been set - see if a slot_list was given
|
||||
*/
|
||||
if (NULL != opal_paffinity_base_slot_list) {
|
||||
/* It's an error if multiple paffinity schemes were specified */
|
||||
if (opal_paffinity_alone) {
|
||||
ret = OMPI_ERR_BAD_PARAM;
|
||||
error = "Multiple processor affinity schemes specified (can only specify one)";
|
||||
goto error;
|
||||
}
|
||||
ret = opal_paffinity_base_slot_list_set((long)ORTE_PROC_MY_NAME->vpid, opal_paffinity_base_slot_list);
|
||||
if (OPAL_ERR_NOT_FOUND != ret) {
|
||||
error = "opal_paffinity_base_slot_list_set() returned an error";
|
||||
goto error;
|
||||
}
|
||||
if (OPAL_SUCCESS == ret) {
|
||||
/* paffinity is supported - check for binding */
|
||||
OPAL_PAFFINITY_PROCESS_IS_BOUND(mask, &proc_bound);
|
||||
if (proc_bound) {
|
||||
/* someone external set it - indicate it is set
|
||||
* so that we know
|
||||
*/
|
||||
paffinity_enabled = true;
|
||||
} else if (opal_paffinity_alone) {
|
||||
/* no slot_list, but they asked for paffinity */
|
||||
int phys_cpu;
|
||||
orte_node_rank_t nrank;
|
||||
if (ORTE_NODE_RANK_INVALID == (nrank = orte_ess.get_node_rank(ORTE_PROC_MY_NAME))) {
|
||||
error = "Could not get node rank - cannot set processor affinity";
|
||||
goto error;
|
||||
} else {
|
||||
/* the system is capable of doing processor affinity, but it
|
||||
* has not yet been set - see if a slot_list was given
|
||||
*/
|
||||
if (NULL != opal_paffinity_base_slot_list) {
|
||||
/* It's an error if multiple paffinity schemes were specified */
|
||||
if (opal_paffinity_alone) {
|
||||
ret = OMPI_ERR_BAD_PARAM;
|
||||
error = "Multiple processor affinity schemes specified (can only specify one)";
|
||||
goto error;
|
||||
}
|
||||
ret = opal_paffinity_base_slot_list_set((long)ORTE_PROC_MY_NAME->vpid, opal_paffinity_base_slot_list);
|
||||
if (OPAL_ERR_NOT_FOUND != ret) {
|
||||
error = "opal_paffinity_base_slot_list_set() returned an error";
|
||||
goto error;
|
||||
}
|
||||
paffinity_enabled = true;
|
||||
} else if (opal_paffinity_alone) {
|
||||
/* no slot_list, but they asked for paffinity */
|
||||
int phys_cpu;
|
||||
orte_node_rank_t nrank;
|
||||
if (ORTE_NODE_RANK_INVALID == (nrank = orte_ess.get_node_rank(ORTE_PROC_MY_NAME))) {
|
||||
error = "Could not get node rank - cannot set processor affinity";
|
||||
goto error;
|
||||
}
|
||||
OPAL_PAFFINITY_CPU_ZERO(mask);
|
||||
phys_cpu = opal_paffinity_base_get_physical_processor_id(nrank);
|
||||
if (0 > phys_cpu) {
|
||||
error = "Could not get physical processor id - cannot set processor affinity";
|
||||
goto error;
|
||||
}
|
||||
OPAL_PAFFINITY_CPU_SET(phys_cpu, mask);
|
||||
ret = opal_paffinity_base_set(mask);
|
||||
if (OPAL_SUCCESS != ret) {
|
||||
error = "Setting processor affinity failed";
|
||||
goto error;
|
||||
}
|
||||
paffinity_enabled = true;
|
||||
}
|
||||
OPAL_PAFFINITY_CPU_ZERO(mask);
|
||||
phys_cpu = opal_paffinity_base_get_physical_processor_id(nrank);
|
||||
if (0 > phys_cpu) {
|
||||
error = "Could not get physical processor id - cannot set processor affinity";
|
||||
goto error;
|
||||
}
|
||||
OPAL_PAFFINITY_CPU_SET(phys_cpu, mask);
|
||||
ret = opal_paffinity_base_set(mask);
|
||||
if (OPAL_SUCCESS != ret) {
|
||||
error = "Setting processor affinity failed";
|
||||
goto error;
|
||||
}
|
||||
paffinity_enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* If we were able to set processor affinity, try setting up
|
||||
memory affinity */
|
||||
if (!opal_maffinity_setup && paffinity_enabled) {
|
||||
|
@ -42,10 +42,14 @@ int opal_paffinity_base_set(opal_paffinity_base_cpu_set_t cpumask)
|
||||
|
||||
int opal_paffinity_base_get(opal_paffinity_base_cpu_set_t *cpumask)
|
||||
{
|
||||
/* zero the cpumask so we start with a clean slate - do
|
||||
* it here so that any error returns no info
|
||||
*/
|
||||
if (NULL != cpumask) {
|
||||
OPAL_PAFFINITY_CPU_ZERO(*cpumask);
|
||||
}
|
||||
|
||||
if (!opal_paffinity_base_selected) {
|
||||
if(NULL != cpumask) {
|
||||
OPAL_PAFFINITY_CPU_ZERO(*cpumask);
|
||||
}
|
||||
return OPAL_ERR_NOT_FOUND;
|
||||
}
|
||||
if(NULL == cpumask) {
|
||||
|
@ -185,6 +185,24 @@ typedef struct opal_paffinity_base_cpu_set_t {
|
||||
#define OPAL_PAFFINITY_CPU_ISSET(num, cpuset) \
|
||||
(0 != (((cpuset).bitmask[OPAL_PAFFINITY_CPU_BYTE(num)]) & ((opal_paffinity_base_bitmask_t) 1 << OPAL_PAFFINITY_CPU_BIT(num))))
|
||||
|
||||
/**
|
||||
* Public macro to test if a process is bound anywhere
|
||||
*/
|
||||
#define OPAL_PAFFINITY_PROCESS_IS_BOUND(cpuset, bound) \
|
||||
do { \
|
||||
int i, num_processors, num_bound; \
|
||||
opal_paffinity_base_get_processor_info(&num_processors); \
|
||||
*(bound) = false; \
|
||||
for (i=0; i < num_processors; i++) { \
|
||||
if (OPAL_PAFFINITY_CPU_ISSET(i, (cpuset))) { \
|
||||
num_bound++; \
|
||||
} \
|
||||
} \
|
||||
if (num_bound < num_processors) { \
|
||||
*(bound) = true; \
|
||||
} \
|
||||
} while(0);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/**
|
||||
@ -201,9 +219,10 @@ typedef int (*opal_paffinity_base_module_set_fn_t)(opal_paffinity_base_cpu_set_t
|
||||
|
||||
/**
|
||||
* Module function to get this process' affinity to a specific set of
|
||||
* PHYSICAL CPUs. Returns OPAL_ERR_NOT_FOUND if
|
||||
* opal_paffinity_base_module_set_fn_t() was not previously invoked in
|
||||
* this process.
|
||||
* PHYSICAL CPUs. Returns any binding in the cpumask. This function -only-
|
||||
* returns something other than OPAL_SUCCESS if an actual error is encountered.
|
||||
* You will need to check the mask to find out if this process is actually
|
||||
* bound somewhere specific - a macro for that purpose is provided above
|
||||
*/
|
||||
typedef int (*opal_paffinity_base_module_get_fn_t)(opal_paffinity_base_cpu_set_t *cpumask);
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user