1
/* $Id: shmtest.c,v 1.6 2003-10-22 22:12:21 d3h325 Exp $ */
13
int armci_test_allocate(long size)
16
long id = (long)shmget(IPC_PRIVATE, (size_t) size, (int) (IPC_CREAT |00600));
19
/* attach to segment */
20
ptr = shmat((int) id, (char *) NULL, 0);
25
/* delete segment id */
26
if(shmctl( (int) id, IPC_RMID,(struct shmid_ds *)NULL))
27
fprintf(stderr,"failed to remove shm id=%d\n",id);
30
if (((long)ptr) == -1L) return 0;
35
/* parameters that define range and granularity of search for shm segment size
36
* UBOUND is chosen to be < 2GB to avoid overflowing on 32-bit systems
37
* smaller PAGE gives more accurate results but with more search steps
38
* LBOUND is set to amount that is considered insufficient for our purposes
42
#define UBOUND 2*4096*PAGE
47
/*\ determine the max shmem segment size using bisection
49
void armci_shmem_init()
52
long upper_bound=UBOUND;
57
int rc = armci_test_allocate(x);
59
if(verbose)printf("test %d size=%ld bytes: success\n",i,x);
61
step = (upper_bound -x)>>1;
62
if(step < 16*PAGE) break;
65
if(verbose)printf("test %d size=%ld bytes: failed\n",i,x);
67
step = (x-lower_bound)>>1;
68
if(step< PAGE || x < LBOUND) break;
74
printf("no usable amount (%d bytes) of shared memory available\n",LBOUND);
75
else printf("%ld bytes segment size, %d calls \n",y,i);
82
main(int argc, char **argv)
85
if(verbose)printf("Searching for max shared memory segment size (SHMMAX) using bisection\n");