dnl -*- shell-script -*- # # $Id: lam_get_shmmax.m4,v 1.1 2000/10/17 12:05:18 jsquyres Exp $ # # This file is part of the University of Notre Dame implementation of # LAM/MPI. See the LICENSE file in the top-level directory for # license and copyright details. define(LAM_GET_SHMMAX,[ # Determine maximum shared segment size. cat > conftest.c < #include #include #include #define LAM_SHMSHORT $1 #define LAM_SHMPOOL $$2 #define MB (1024*1024) int test_alloc(int size) { char *base; int shmid; shmid = shmget(IPC_PRIVATE, size, 0600 | IPC_CREAT); if (shmid < 0) return(0); base = (char *) shmat(shmid, (char *) 0, 0); if (base == (char *) -1) { shmctl(shmid, IPC_RMID, (struct shmid_ds *) 0); return(0); } shmdt(base); shmctl(shmid, IPC_RMID, (struct shmid_ds *) 0); return(1); } int main(int argc, char* argv[]) { int poolsize, maxalloc; FILE *f=fopen("conftestval", "w"); if (!f) return 1; if (LAM_SHMPOOL > 0) { if (LAM_SHMPOOL >= 2 * MB) maxalloc = MB; else maxalloc = LAM_SHMPOOL; fprintf(f, "%d\t%d\t%d\n", 0, LAM_SHMPOOL, maxalloc); fclose(f); return(0); } if (test_alloc(32*MB)) { poolsize = 16*MB; maxalloc = MB; } else if (test_alloc(16*MB)) { poolsize = 14*MB; maxalloc = MB; } else if (test_alloc(8*MB)) { poolsize = 6*MB; maxalloc = MB; } else if (test_alloc(4*MB)) { poolsize = 2*MB; maxalloc = MB; } else if (test_alloc(2*MB)) { poolsize = MB; maxalloc = MB/2; } else if (test_alloc(MB)) { poolsize = MB - (8*7 * (LAM_SHMSHORT+128)) - 256; if (poolsize < 0) poolsize = MB - (4*3 * (LAM_SHMSHORT+128)) - 256; if (poolsize < 0) poolsize = 0; maxalloc = poolsize; } else { poolsize = 0; maxalloc = 0; } fprintf(f, "%d\t%d\n", poolsize, maxalloc); fclose(f); return(0); } EOF $CC $CFLAGS -o conftest conftest.c 1>&5 2>&1 if test -s conftest && (./conftest; exit) 2>/dev/null; then if test [$]$2 -eq 0; then $2=`cat conftestval | cut -f1` fi if test [$]$3 -eq 0; then $3=`cat conftestval | cut -f2` fi else echo AC_MSG_WARN(error compiling/running conftest) lam_echo "using default of" if test [$]$2 -eq 0; then $2=524288 fi if test [$]$3 -eq 0; then $3=524288 fi fi /bin/rm -f conftest*])dnl