5
/* $Id: shmalloc.c,v 1.10 2002-06-20 23:34:17 vinod Exp $ */
14
#include "kr_malloc.h"
16
static long *offset_arr;
18
void armci_shmalloc_exchange_offsets(context_t *ctx_local)
22
armci_size_t bytes = 128;
25
ptr_arr = (void**)malloc(armci_nproc*sizeof(void*));
26
offset_arr = (long*) malloc(armci_nproc*sizeof(long));
27
if(!ptr_arr || !offset_arr) armci_die("armci_shmalloc_get_offsets: malloc failed", 0);
29
/* get memory with same size on all procs */
30
ptr = kr_malloc(bytes, ctx_local);
31
if(!ptr) armci_die("armci_shmalloc_get_offsets: kr_malloc failed",bytes);
33
bzero((char*)ptr_arr,armci_nproc*sizeof(void*));
34
ptr_arr[armci_me] = ptr;
36
/* now combine individual addresses into a single array */
37
armci_exchange_address(ptr_arr, armci_nproc);
40
for (i=0; i<armci_nproc; i++)
42
offset_arr[i] = (long) ((char*)ptr - (char*)ptr_arr[i]);
46
kr_free(ptr, ctx_local);
49
void armci_shmalloc_exchange_address(void **ptr_arr)
53
/* now combine individual addresses into a single array */
54
armci_exchange_address(ptr_arr, armci_nproc);
56
/* since shmalloc may not give symmetric addresses (especially on Linux),
57
* adjust addresses based on offset calculated during initialization */
58
for (i=0; i<armci_nproc; i++)
60
ptr_arr[i] = (char*)ptr_arr[i] + offset_arr[i];
66
extern int ARMCI_Absolute_id(ARMCI_Group *group,int group_rank);
68
/* group based exchange address */
69
void armci_shmalloc_exchange_address_grp(void **ptr_arr, ARMCI_Group *group)
74
ARMCI_Group_size(group, &grp_nproc);
76
/* now combine individual addresses into a single array */
77
armci_exchange_address_grp(ptr_arr, grp_nproc, group);
79
/* since shmalloc may not give symmetric addresses (especially on Linux),
80
* adjust addresses based on offset calculated during initialization */
81
for (i=0; i<grp_nproc; i++)
83
world_rank = ARMCI_Absolute_id(group,i);
84
ptr_arr[i] = (char*)ptr_arr[i] + offset_arr[world_rank];
89
/* get the remote process's pointer */
90
void* armci_shmalloc_remote_addr(void *ptr, int proc)
92
return (void*)((char*)ptr - offset_arr[proc]);
97
#define XT_SYMMETRIC_HEAP_SIZE ((size_t)1024)*1024*1024; /* 1 GB is default */
98
size_t get_xt_heapsize()
101
char *uval = getenv("XT_SYMMETRIC_HEAP_SIZE");
103
char *unit_str = NULL;
104
size_t scale=1, size;
108
if((unit_str=strchr(uval, 'K')) != NULL)
111
token = strtok(uval, "K");
113
else if((unit_str=strchr(uval, 'M')) != NULL)
115
scale = ((size_t)1024)*1024;
116
token = strtok(uval, "M");
118
else if((unit_str=strchr(uval, 'G')) != NULL)
120
scale = ((size_t)1024)*1024*1024;
121
token = strtok(uval, "G");
129
size = (size_t)atol(token);
130
size *= scale; /* in bytes */
133
armci_die("get_xt_heapsize(): Symmetric heapsize should be > 1MB",0);
137
size = XT_SYMMETRIC_HEAP_SIZE;
142
#endif /* defined CRAY_XT */