|
13 | 13 | * Copyright (c) 2007-2012 Los Alamos National Security, LLC. All rights
|
14 | 14 | * reserved.
|
15 | 15 | * Copyright (c) 2013-2014 Intel, Inc. All rights reserved
|
16 |
| - * Copyright (c) 2015 Research Organization for Information Science |
| 16 | + * Copyright (c) 2015-2016 Research Organization for Information Science |
17 | 17 | * and Technology (RIST). All rights reserved.
|
18 | 18 | * $COPYRIGHT$
|
19 | 19 | *
|
@@ -369,17 +369,66 @@ static inline bool ompi_proc_is_sentinel (ompi_proc_t *proc)
|
369 | 369 | return (intptr_t) proc & 0x1;
|
370 | 370 | }
|
371 | 371 |
|
372 |
| -static inline intptr_t ompi_proc_name_to_sentinel (opal_process_name_t name) |
| 372 | +#if OPAL_SIZEOF_PROCESS_NAME_T == SIZEOF_VOID_P |
| 373 | +/* |
| 374 | + * we assume an ompi_proc_t is at least aligned on two bytes, |
| 375 | + * so if the LSB of a pointer to an ompi_proc_t is 1, we have to handle |
| 376 | + * this pointer as a sentinel instead of a pointer. |
| 377 | + * a sentinel can be seen as an uint64_t with the following format : |
| 378 | + * - bit 0 : 1 |
| 379 | + * - bits 1-15 : local jobid |
| 380 | + * - bits 16-31 : job family |
| 381 | + * - bits 32-63 : vpid |
| 382 | + */ |
| 383 | +static inline uintptr_t ompi_proc_name_to_sentinel (opal_process_name_t name) |
| 384 | +{ |
| 385 | + uintptr_t tmp, sentinel = 0; |
| 386 | + /* local jobid must fit in 15 bits */ |
| 387 | + assert(! (OMPI_LOCAL_JOBID(name.jobid) & 0x8000)); |
| 388 | + sentinel |= 0x1; |
| 389 | + tmp = (uintptr_t)OMPI_LOCAL_JOBID(name.jobid); |
| 390 | + sentinel |= ((tmp << 1) & 0xfffe); |
| 391 | + tmp = (uintptr_t)OMPI_JOB_FAMILY(name.jobid); |
| 392 | + sentinel |= ((tmp << 16) & 0xffff0000); |
| 393 | + tmp = (uintptr_t)name.vpid; |
| 394 | + sentinel |= ((tmp << 32) & 0xffffffff00000000); |
| 395 | + return sentinel; |
| 396 | +} |
| 397 | + |
| 398 | +static inline opal_process_name_t ompi_proc_sentinel_to_name (uintptr_t sentinel) |
| 399 | +{ |
| 400 | + opal_process_name_t name; |
| 401 | + uint32_t local, family; |
| 402 | + uint32_t vpid; |
| 403 | + assert(sentinel & 0x1); |
| 404 | + local = (sentinel >> 1) & 0x7fff; |
| 405 | + family = (sentinel >> 16) & 0xffff; |
| 406 | + vpid = (sentinel >> 32) & 0xffffffff; |
| 407 | + name.jobid = OMPI_CONSTRUCT_JOBID(family,local); |
| 408 | + name.vpid = vpid; |
| 409 | + return name; |
| 410 | +} |
| 411 | +#elif 4 == SIZEOF_VOID_P |
| 412 | +/* |
| 413 | + * currently, a sentinel is only made from the current jobid aka OMPI_PROC_MY_NAME->jobid |
| 414 | + * so we only store the first 31 bits of the vpid |
| 415 | + */ |
| 416 | +static inline uintptr_t ompi_proc_name_to_sentinel (opal_process_name_t name) |
373 | 417 | {
|
374 |
| - return (*((intptr_t *) &name) << 1) | 0x1; |
| 418 | + assert(OMPI_PROC_MY_NAME->jobid == name.jobid); |
| 419 | + return (uintptr_t)((name.vpid <<1) | 0x1); |
375 | 420 | }
|
376 | 421 |
|
377 |
| -static inline opal_process_name_t ompi_proc_sentinel_to_name (intptr_t sentinel) |
| 422 | +static inline opal_process_name_t ompi_proc_sentinel_to_name (uintptr_t sentinel) |
378 | 423 | {
|
379 |
| - sentinel >>= 1; |
380 |
| - sentinel &= 0x7FFFFFFFFFFFFFFF; |
381 |
| - return *((opal_process_name_t *) &sentinel); |
| 424 | + opal_process_name_t name; |
| 425 | + name.jobid = OMPI_PROC_MY_NAME->jobid; |
| 426 | + name.vpid = sentinel >> 1; |
| 427 | + return name; |
382 | 428 | }
|
| 429 | +#else |
| 430 | +#error unsupported pointer size |
| 431 | +#endif |
383 | 432 |
|
384 | 433 | END_C_DECLS
|
385 | 434 |
|
|
0 commit comments