5
/* $Id: shmalloc.c,v 1.10 2002-06-20 23:34:17 vinod Exp $ */
10
#include "kr_malloc.h"
12
static long *offset_arr;
14
void armci_shmalloc_exchange_offsets(context_t *ctx_local)
18
armci_size_t bytes = 128;
21
ptr_arr = (void**)malloc(armci_nproc*sizeof(void*));
22
offset_arr = (long*) malloc(armci_nproc*sizeof(long));
23
if(!ptr_arr || !offset_arr) armci_die("armci_shmalloc_get_offsets: malloc failed", 0);
25
/* get memory with same size on all procs */
26
ptr = kr_malloc(bytes, ctx_local);
27
if(!ptr) armci_die("armci_shmalloc_get_offsets: kr_malloc failed",bytes);
29
bzero((char*)ptr_arr,armci_nproc*sizeof(void*));
30
ptr_arr[armci_me] = ptr;
32
/* now combine individual addresses into a single array */
33
armci_exchange_address(ptr_arr, armci_nproc);
36
for (i=0; i<armci_nproc; i++)
38
offset_arr[i] = (long) ((char*)ptr - (char*)ptr_arr[i]);
42
kr_free(ptr, ctx_local);
45
void armci_shmalloc_exchange_address(void **ptr_arr)
49
/* now combine individual addresses into a single array */
50
armci_exchange_address(ptr_arr, armci_nproc);
52
/* since shmalloc may not give symmetric addresses (especially on Linux),
53
* adjust addresses based on offset calculated during initialization */
54
for (i=0; i<armci_nproc; i++)
56
ptr_arr[i] = (char*)ptr_arr[i] + offset_arr[i];
62
extern int ARMCI_Absolute_id(ARMCI_Group *group,int group_rank);
64
/* group based exchange address */
65
void armci_shmalloc_exchange_address_grp(void **ptr_arr, ARMCI_Group *group)
70
ARMCI_Group_size(group, &grp_nproc);
72
/* now combine individual addresses into a single array */
73
armci_exchange_address_grp(ptr_arr, grp_nproc, group);
75
/* since shmalloc may not give symmetric addresses (especially on Linux),
76
* adjust addresses based on offset calculated during initialization */
77
for (i=0; i<grp_nproc; i++)
79
world_rank = ARMCI_Absolute_id(group,i);
80
ptr_arr[i] = (char*)ptr_arr[i] + offset_arr[world_rank];
85
/* get the remote process's pointer */
86
void* armci_shmalloc_remote_addr(void *ptr, int proc)
88
return (void*)((char*)ptr - offset_arr[proc]);