~ubuntu-branches/ubuntu/trusty/nwchem/trusty-proposed

« back to all changes in this revision

Viewing changes to src/tools/ga-5-2/armci/src-portals/shmem.c

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Daniel Leidert, Andreas Tille, Michael Banck
  • Date: 2013-07-04 12:14:55 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130704121455-5tvsx2qabor3nrui
Tags: 6.3-1
* New upstream release.
* Fixes anisotropic properties (Closes: #696361).
* New features include:
  + Multi-reference coupled cluster (MRCC) approaches
  + Hybrid DFT calculations with short-range HF 
  + New density-functionals including Minnesota (M08, M11) and HSE hybrid
    functionals
  + X-ray absorption spectroscopy (XAS) with TDDFT
  + Analytical gradients for the COSMO solvation model
  + Transition densities from TDDFT 
  + DFT+U and Electron-Transfer (ET) methods for plane wave calculations
  + Exploitation of space group symmetry in plane wave geometry optimizations
  + Local density of states (LDOS) collective variable added to Metadynamics
  + Various new XC functionals added for plane wave calculations, including
    hybrid and range-corrected ones
  + Electric field gradients with relativistic corrections 
  + Nudged Elastic Band optimization method
  + Updated basis sets and ECPs 

[ Daniel Leidert ]
* debian/watch: Fixed.

[ Andreas Tille ]
* debian/upstream: References

[ Michael Banck ]
* debian/upstream (Name): New field.
* debian/patches/02_makefile_flags.patch: Refreshed.
* debian/patches/06_statfs_kfreebsd.patch: Likewise.
* debian/patches/07_ga_target_force_linux.patch: Likewise.
* debian/patches/05_avoid_inline_assembler.patch: Removed, no longer needed.
* debian/patches/09_backported_6.1.1_fixes.patch: Likewise.
* debian/control (Build-Depends): Added gfortran-4.7 and gcc-4.7.
* debian/patches/10_force_gcc-4.7.patch: New patch, explicitly sets
  gfortran-4.7 and gcc-4.7, fixes test suite hang with gcc-4.8 (Closes:
  #701328, #713262).
* debian/testsuite: Added tests for COSMO analytical gradients and MRCC.
* debian/rules (MRCC_METHODS): New variable, required to enable MRCC methods.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if HAVE_CONFIG_H
 
2
#   include "config.h"
 
3
#endif
 
4
 
 
5
/* $Id: shmem.c,v 1.87.2.2 2007-09-10 23:31:32 manoj Exp $ */
 
6
/* System V shared memory allocation and managment
 
7
 *
 
8
 * Interface:
 
9
 * ~~~~~~~~~
 
10
 *  char *Create_Shared_Region(long *idlist, long size, long *offset)
 
11
 *       . to be called by just one process. 
 
12
 *       . calls kr_malloc,  malloc-like memory allocator from the K&R book. 
 
13
 *         kr_malloc inturn calls armci_allocate() that does shmget() and shmat(). 
 
14
 *       . idlist might be just a pointer to integer or a true array in the
 
15
 *         MULTIPLE_REGIONS versions (calling routine has to take care of it) 
 
16
 *  char *Attach_Shared_Region(long *idlist, long size, long offset)
 
17
 *       . called by any other process to attach to existing shmem region or
 
18
 *         if attached just calculate the address based on the offset
 
19
 *       . has to be called after shmem region was created
 
20
 *  void  Free_Shmem_Ptr(long id, long size, char* addr)
 
21
 *       . called ONLY by the process that created shmem region (id) to return
 
22
 *         pointer to kr_malloc (shmem is not destroyed)
 
23
 *  void  Delete_All_Regions()
 
24
 *       . destroys all shared memory regions
 
25
 *       . can be called by any process assuming that all processes attached
 
26
 *         to alllocated shmem regions 
 
27
 *       . needs to by called by cleanup procedure(s)
 
28
 *
 
29
 * Jarek Nieplocha, 06.13.94
 
30
 * 
 
31
 */
 
32
 
 
33
#ifdef SYSV
 
34
 
 
35
 
 
36
#define DEBUG_ 0
 
37
#define DEBUG1 0
 
38
#define DEBUG2_ 0
 
39
 
 
40
/* For debugging purposes at the beginning of the shared memory region
 
41
 * creator process can write a stamp which then is read by attaching processes
 
42
 * NOTE: on clusters we cannot use it anymore since ARMCI node master
 
43
 * uses it since Nov 99 to write the value of address it attached at
 
44
 * This feature is used in the ARMCI memlock table.
 
45
 */
 
46
#define STAMP 0
 
47
 
 
48
 
 
49
#include <sys/types.h>
 
50
#include <sys/ipc.h>
 
51
#include <sys/shm.h>
 
52
#include <sys/sem.h>
 
53
#include <sys/param.h>
 
54
#include <errno.h>
 
55
#include <stdio.h>
 
56
#include <stdlib.h>
 
57
#include "shmem.h"
 
58
#include "kr_malloc.h"
 
59
#include "shmlimit.h"
 
60
#include "message.h"
 
61
#include "armcip.h"
 
62
 
 
63
#ifdef   ALLOC_MUNMAP
 
64
#include <sys/mman.h>
 
65
#include <unistd.h>
 
66
static  size_t pagesize=0;
 
67
static  int logpagesize=0;
 
68
/* allow only that big shared memory segment (in MB)- incresed from 128 11/02 */
 
69
#define MAX_ALLOC_MUNMAP 128
 
70
#define MAX_ALLOC_MUNMAP_ 368
 
71
static long max_alloc_munmap=MAX_ALLOC_MUNMAP;
 
72
#endif
 
73
 
 
74
#if defined(SUN)
 
75
  extern char *shmat();
 
76
#endif
 
77
 
 
78
#define SHM_UNIT (1024)
 
79
 
 
80
 
 
81
/* Need to determine the max shmem segment size. There are 2 alternatives:
 
82
 * 1. use predefined SHMMAX if available or set some reasonable values, or
 
83
 * 2. trial-and-error search for a max value (default)
 
84
 *    case a) fork a process to determine shmmax size (more accurate)
 
85
 *    case b) search w/o forking until success (less accurate)
 
86
 */
 
87
 
 
88
/* under Myrinet GM, we cannot fork */
 
89
#if defined(GM) || defined(VAPI)
 
90
#   define SHMMAX_SEARCH_NO_FORK 
 
91
#endif
 
92
#if defined(LAPI) || defined(AIX) || defined(SHMMAX_SEARCH_NO_FORK) || defined(CRAY_XT)
 
93
#   define NO_SHMMAX_SEARCH
 
94
#endif
 
95
 
 
96
/* Limits for the largest shmem segment are in Kilobytes to avoid passing
 
97
 * Gigavalues to kr_malloc
 
98
 * the limit for the KSR is lower than SHMMAX in sys/param.h because
 
99
 * shmat would fail -- SHMMAX cannot be trusted (a bug)
 
100
 */
 
101
#define _SHMMAX 4*1024
 
102
 
 
103
#if defined(SUN)||defined(SOLARIS)
 
104
#  undef _SHMMAX
 
105
#  define _SHMMAX (1024)  /* memory in KB */
 
106
#elif defined(SGI64) || defined(AIX) || defined(CONVEX)
 
107
#  undef _SHMMAX
 
108
#  define _SHMMAX ((unsigned long)512*1024)
 
109
#elif defined(SGI) && !defined(SGI64)
 
110
#  undef _SHMMAX
 
111
#  define _SHMMAX ((unsigned long)128*1024)
 
112
#elif defined(KSR)
 
113
#  undef _SHMMAX
 
114
#  define _SHMMAX ((unsigned long)512*1024)
 
115
#elif defined(HPUX)
 
116
#  undef _SHMMAX
 
117
#  define _SHMMAX ((unsigned long)64*1024)
 
118
#elif defined(__FreeBSD__)
 
119
#  undef _SHMMAX
 
120
#  define _SHMMAX ((unsigned long)3*1024)
 
121
#elif defined(LINUX) 
 
122
#  if !defined(SHMMAX) /* Red Hat does not define SHMMAX */
 
123
#     undef _SHMMAX
 
124
#     if defined(__sparc__) || defined(__powerpc__) 
 
125
#       define _SHMMAX ((unsigned long)16*1024)
 
126
#     elif defined(__alpha__)
 
127
#       define _SHMMAX ((unsigned long)4072)
 
128
#     else
 
129
        /* Intel */
 
130
#       define _SHMMAX ((unsigned long)32*1024)
 
131
#     endif
 
132
#  endif
 
133
#elif defined(SHMMAX)
 
134
#  undef _SHMMAX
 
135
#  define _SHMMAX (((unsigned long)SHMMAX)>>10)
 
136
#endif
 
137
 
 
138
static  unsigned long MinShmem_per_core = 0;
 
139
static  unsigned long MaxShmem_per_core = 0;
 
140
static  unsigned long MinShmem = _SHMMAX;  
 
141
static  unsigned long MaxShmem = MAX_REGIONS*_SHMMAX;
 
142
static  context_t ctx_shmem; /* kr_malloc context */ 
 
143
static  context_t *ctx_shmem_global; /* kr_malloc context stored in shmem */
 
144
static  int create_call=0;
 
145
 
 
146
#ifdef  SHMMAX_SEARCH_NO_FORK
 
147
static  char *ptr_search_no_fork = (char*)0;
 
148
static  int id_search_no_fork=0;
 
149
#endif
 
150
 
 
151
 
 
152
#ifdef LINUX
 
153
#define CLEANUP_CMD(command) sprintf(command,"/usr/bin/ipcrm shm %d",id);
 
154
#elif  defined(SOLARIS) 
 
155
#define CLEANUP_CMD(command) sprintf(command,"/bin/ipcrm -m %d",id);
 
156
#elif  defined(SGI) 
 
157
#define CLEANUP_CMD(command) sprintf(command,"/usr/sbin/ipcrm -m %d",id);
 
158
#else
 
159
#define CLEANUP_CMD(command) sprintf(command,"/usr/bin/ipcrm -m %d",id);
 
160
#endif
 
161
 
 
162
 
 
163
#ifdef   ALLOC_MUNMAP
 
164
#ifdef QUADRICS
 
165
#  include <elan/elan.h>
 
166
#  include <elan3/elan3.h>
 
167
   static  char *armci_elan_starting_address = (char*)0;
 
168
 
 
169
#  ifdef __ia64__
 
170
#    define ALLOC_MUNMAP_ALIGN 1024*1024
 
171
#  else
 
172
#    define ALLOC_MUNMAP_ALIGN 64*1024
 
173
#  endif
 
174
 
 
175
#  define ALGN_MALLOC(s,a) elan_allocMain(elan_base->state, (a), (s))
 
176
#else 
 
177
#  define ALGN_MALLOC(s,a) malloc((s))
 
178
#endif
 
179
 
 
180
static char* alloc_munmap(size_t size)
 
181
{
 
182
char *tmp;
 
183
unsigned long iptr;
 
184
size_t bytes = size+pagesize-1;
 
185
 
 
186
    if(armci_elan_starting_address){
 
187
       tmp = armci_elan_starting_address;
 
188
       armci_elan_starting_address += size; 
 
189
#      ifdef ALLOC_MUNMAP_ALIGN
 
190
         armci_elan_starting_address += ALLOC_MUNMAP_ALIGN;
 
191
#      endif
 
192
       if(DEBUG_) {printf("%d: address for shm attachment is %p size=%ld\n",
 
193
                         armci_me,tmp,(long)size); fflush(stdout); }
 
194
    } else {
 
195
      tmp = ALGN_MALLOC(bytes, getpagesize());
 
196
      if(tmp){
 
197
        iptr = (unsigned long)tmp + pagesize-1;
 
198
        iptr >>= logpagesize; iptr <<= logpagesize;
 
199
        if(DEBUG_) printf("%d:unmap ptr=%p->%p size=%d pagesize=%d\n",armci_me, 
 
200
                          tmp,(char*)iptr,(int)size,pagesize);
 
201
        tmp = (char*)iptr;
 
202
        if(munmap(tmp, size) == -1) armci_die("munmap failed",0);
 
203
        if(DEBUG_){printf("%d: unmap OK\n",armci_me); fflush(stdout);}
 
204
      }else armci_die("alloc_munmap: malloc failed",(int)size);
 
205
    }
 
206
    return tmp;
 
207
}
 
208
#endif
 
209
 
 
210
/*\ A wrapper to shmget. Just to be sure that ID is not 0.
 
211
\*/
 
212
int armci_shmget(size_t size,char *from)
 
213
{
 
214
int id;
 
215
 
 
216
    id = shmget(IPC_PRIVATE, size, (IPC_CREAT | 00600));
 
217
 
 
218
    /*attaching with id 0 somehow fails (Seen on pentium4+linux24+gm163)
 
219
     *so if id=0, shmget again. */
 
220
    while(id==0){
 
221
       /* free id=0 and get a new one */
 
222
       if(shmctl((int)id,IPC_RMID,(struct shmid_ds *)NULL)) {
 
223
         fprintf(stderr,"id=%d \n",id);
 
224
         armci_die("allocate: failed to _delete_ shared region ",id);
 
225
       }
 
226
       id = shmget(IPC_PRIVATE, size, (IPC_CREAT | 00600));
 
227
    }
 
228
    if(DEBUG_){
 
229
       printf("\n%d:armci_shmget sz=%ld caller=%s id=%d\n",armci_me,(long)size,
 
230
               from,id);
 
231
       fflush(stdout);
 
232
    }
 
233
    return(id);
 
234
}
 
235
 
 
236
static int 
 
237
Semget(key_t key,int nsems,int semflg) {
 
238
      int ret;
 
239
 
 
240
      if((ret = semget(key,nsems,semflg)) == -1) {
 
241
         switch(errno) {
 
242
           case EACCES: fprintf(stdout," semget errno=EACCES.\n"); break;
 
243
           case EINVAL: fprintf(stdout," semget errno=EINVAL.\n"); break;
 
244
           case ENOENT: fprintf(stdout," semget errno=ENOENT.\n"); break;
 
245
           case ENOSPC: fprintf(stdout," semget errno=ENOSPC -- check system limit for sysv semaphores.\n"); break;
 
246
           case ENOMEM: fprintf(stdout," semget errno=ENOMEM.\n"); break;
 
247
           case EEXIST: fprintf(stdout," semget errno=EEXIST.\n"); break;
 
248
           default:
 
249
             fprintf(stdout," unusual semget errno=%d\n",errno); break;
 
250
         }
 
251
         armci_die("semget failed",errno);
 
252
      }
 
253
 
 
254
      return ret;
 
255
}
 
256
 
 
257
 
 
258
int armci_semget(int count) 
 
259
{
 
260
        int id;
 
261
        id = Semget(IPC_PRIVATE,2,0600);
 
262
        return id;
 
263
}
 
264
 
 
265
int armci_semrm(int id) 
 
266
{
 
267
        semctl(id,0,IPC_RMID);
 
268
}
 
269
 
 
270
int armci_shmrm(int id)
 
271
{
 
272
        int ret;
 
273
        if((ret = shmctl(id,IPC_RMID,NULL)) != 0) {
 
274
          fprintf(stdout,"[cp]: shmctl return an error.\n");
 
275
          switch(errno) {
 
276
            case EINVAL:
 
277
              fprintf(stdout," Error EINVAL: shmid is not a valid shared memory segment.\n");
 
278
              break;
 
279
            case EFAULT:
 
280
              fprintf(stdout," Error EFAULT: argument 3 is not a valid struct shmid_ds.\n");
 
281
              break;
 
282
            case EPERM:
 
283
              fprintf(stdout," Error EPREM: permission to access/change shared mem segment denied.\n");
 
284
              break;
 
285
            default:
 
286
              fprintf(stdout," unusual shmctl errno=%d\n",errno); break;
 
287
              break;
 
288
            }
 
289
            armci_die("error deleting shmid",id);
 
290
        }
 
291
        return ret;
 
292
}
 
293
 
 
294
/*\ test is a shared memory region of a specified size can be allocated
 
295
 *  return 0 (no) or 1 (yes)
 
296
\*/
 
297
int armci_test_allocate(long size)
 
298
{
 
299
   char *ptr;
 
300
   int id = armci_shmget((size_t)size,"armci_test_allocate");
 
301
   if (id <0) return 0;
 
302
 
 
303
   /* attach to segment */
 
304
   ptr =  shmat(id, (char *) NULL, 0);
 
305
 
 
306
   /* delete segment id */
 
307
   if(shmctl( id, IPC_RMID, (struct shmid_ds *)NULL))
 
308
      fprintf(stderr,"failed to remove shm id=%d\n",id);
 
309
 
 
310
   /* test pointer */
 
311
   if (((long)ptr) == -1L) return 0;
 
312
   else return 1;
 
313
}
 
314
 
 
315
 
 
316
/*\ try to allocate a shared memory region of a specified size; return pointer
 
317
\*/
 
318
static int armci_shmalloc_try(long size)
 
319
{
 
320
#ifdef  SHMMAX_SEARCH_NO_FORK
 
321
   char *ptr;
 
322
   int id = armci_shmget((size_t) size,"armci_shmalloc_try");
 
323
   if (id <0) return 0;
 
324
 
 
325
   /* attach to segment */
 
326
   ptr =  shmat(id, (char *) NULL, 0);
 
327
 
 
328
   /* test pointer */
 
329
   if (((long)ptr) == -1L) return 0;
 
330
 
 
331
   ptr_search_no_fork = ptr;
 
332
   id_search_no_fork = id;
 
333
#endif
 
334
   return 1;
 
335
}
 
336
 
 
337
 
 
338
 
 
339
 
 
340
/* parameters that define range and granularity of search for shm segment size
 
341
 * UBOUND is chosen to be < 2GB to avoid overflowing on 32-bit systems
 
342
 * smaller PAGE gives more accurate results but with more search steps
 
343
 * LBOUND  is set to minimum amount for our purposes
 
344
 * change UBOUND=512MB if you need larger arrays than 512 MB
 
345
 */
 
346
#define PAGE (16*65536L)
 
347
#define LBOUND  1048576L
 
348
#if defined(MULTI_CTX) && defined(QUADRICS)
 
349
#define UBOUND 256*LBOUND
 
350
#else
 
351
#define UBOUND 512*LBOUND
 
352
#endif
 
353
 
 
354
static long get_user_shmmax()
 
355
{
 
356
char *uval;
 
357
long x=0;
 
358
     uval = getenv("ARMCI_DEFAULT_SHMMAX"); 
 
359
     if(uval != NULL){
 
360
       sscanf(uval,"%ld",&x);
 
361
       if(x<1L || x> 2048L){ 
 
362
          fprintf(stderr,"incorrect ARMCI_DEFAULT_SHMMAX should be <1,2048>mb and 2^N Found=%ld\n",x);
 
363
          x=0;
 
364
       }
 
365
     }
 
366
     return x*1048576; /* return value in bytes */
 
367
}
 
368
 
 
369
/*\ determine the max shmem segment size using bisection
 
370
\*/
 
371
int armci_shmem_test()
 
372
{
 
373
long x;
 
374
int  i,rc;
 
375
long upper_bound=UBOUND;
 
376
long lower_bound=0;
 
377
 
 
378
     x = get_user_shmmax();
 
379
     if(!x) x = upper_bound;
 
380
     else upper_bound =x;
 
381
     
 
382
     if(DEBUG_){printf("%d: x = %ld upper_bound=%ld\n",armci_me, x, upper_bound); fflush(stdout);}
 
383
 
 
384
     for(i=1;;i++){
 
385
        long step;
 
386
        rc = armci_test_allocate(x);
 
387
        if(DEBUG_) 
 
388
           printf("%d:test %d size=%ld bytes status=%d\n",armci_me,i,x,rc);
 
389
        if(rc){
 
390
          lower_bound = x;
 
391
          step = (upper_bound -x)>>1;
 
392
          if(step < PAGE) break;
 
393
          x += step;
 
394
        }else{
 
395
          upper_bound = x;
 
396
          step = (x-lower_bound)>>1;
 
397
          if(step<PAGE) break;
 
398
          x -= step;
 
399
        }
 
400
        /* round it up to a full base-2 MB */
 
401
        x += 1048576L -1L;
 
402
        x >>=20;
 
403
        x <<=20; 
 
404
      }
 
405
 
 
406
      if(!lower_bound){
 
407
          /* try if can get LBOUND - necessary if search starts from UBOUND */
 
408
          lower_bound=LBOUND;
 
409
          rc = armci_test_allocate(lower_bound);
 
410
          if(!rc) return(0);
 
411
      }
 
412
 
 
413
      if(DEBUG_) printf("%ld bytes segment size, %d calls \n",lower_bound,i);
 
414
      return (int)( lower_bound>>20); /* return shmmax in mb */
 
415
}
 
416
 
 
417
 
 
418
#ifdef SHMMAX_SEARCH_NO_FORK
 
419
/*\ determine the max shmem segment size by halving
 
420
\*/
 
421
static int armci_shmem_test_no_fork()                          
 
422
{
 
423
long x;                                                     
 
424
int  i,rc;
 
425
long lower_bound=_SHMMAX*SHM_UNIT;
 
426
#define UBOUND_SEARCH_NO_FORK (256*SHM_UNIT*SHM_UNIT)
 
427
 
 
428
     x = get_user_shmmax();
 
429
     if(!x) x = UBOUND_SEARCH_NO_FORK;
 
430
 
 
431
     for(i=1;;i++){
 
432
 
 
433
        rc = armci_shmalloc_try(x);
 
434
        if(DEBUG_)
 
435
           printf("%d:test by halving size=%ld bytes rc=%d\n",armci_me,x,rc);
 
436
 
 
437
        if(rc){
 
438
          lower_bound = x;
 
439
          break;
 
440
        }else{
 
441
          x >>= 1 ;
 
442
          if(x<lower_bound) break;
 
443
        }
 
444
     }
 
445
 
 
446
     if(DEBUG_) printf("%ld: shmax test no fork: bytes segment size, %d calls \n",lower_bound,i);
 
447
     return (int)( lower_bound>>20); /* return shmmax in mb */
 
448
}
 
449
#endif
 
450
 
 
451
 
 
452
#ifdef MULTI_CTX
 
453
void armci_nattach_preallocate_info(int* segments, int *segsize)
 
454
{
 
455
     int x;
 
456
     char *uval;
 
457
     uval = getenv("LIBELAN_NATTACH");
 
458
     if(uval != NULL){
 
459
        sscanf(uval,"%d",&x);
 
460
        if(x<2 || x>8) armci_die("Error in LIBELAN_NATTACH <8, >1 ",(int)x);
 
461
     }else
 
462
        armci_die("Inconsistent configuration: ARMCI needs LIBELAN_NATTACH",0);
 
463
     *segments =x;
 
464
     *segsize = (int) (SHM_UNIT * MinShmem);
 
465
 
 
466
}
 
467
#endif
 
468
        
 
469
/* Create shared region to store kr_malloc context in shared memory */
 
470
void armci_krmalloc_init_ctxshmem() {
 
471
    void *myptr=NULL;
 
472
    long idlist[SHMIDLEN];
 
473
    long size; 
 
474
    int offset = sizeof(void*)/sizeof(int);
 
475
 
 
476
    /* to store shared memory context and  myptr */
 
477
    size = SHMEM_CTX_MEM;
 
478
    
 
479
    if(armci_me == armci_master ){
 
480
       myptr = Create_Shared_Region(idlist+1,size,idlist);
 
481
       if(!myptr && size>0 ) armci_die("armci_krmalloc_init_ctxshmem: could not create", (int)(size>>10));
 
482
       if(size) *(volatile void**)myptr = myptr;
 
483
       if(DEBUG_){
 
484
          printf("%d:armci_krmalloc_init_ctxshmem addr mptr=%p ref=%p size=%ld\n", armci_me, myptr, *(void**)myptr, size);
 
485
          fflush(stdout);
 
486
       }
 
487
       
 
488
       /* Bootstrapping: allocate storage for ctx_shmem_global. NOTE:there is 
 
489
          offset,as master places its address at begining for others to see */
 
490
       ctx_shmem_global = (context_t*) ( ((int*)myptr)+offset );
 
491
       *ctx_shmem_global = ctx_shmem; /*master copies ctx into shared region */
 
492
    }
 
493
 
 
494
    /* broadcast shmem id to other processes on the same cluster node */
 
495
    armci_msg_clus_brdcst(idlist, SHMIDLEN*sizeof(long));
 
496
 
 
497
    if(armci_me != armci_master){
 
498
       myptr=(double*)Attach_Shared_Region(idlist+1,size,idlist[0]);
 
499
       if(!myptr)armci_die("armci_krmalloc_init_ctxshmem: could not attach", (int)(size>>10));
 
500
       
 
501
       /* now every process in a SMP node needs to find out its offset
 
502
        * w.r.t. master - this offset is necessary to use memlock table
 
503
        */
 
504
       if(size) armci_set_mem_offset(myptr);
 
505
       if(DEBUG_){
 
506
          printf("%d:armci_krmalloc_init_ctxshmem attached addr mptr=%p ref=%p size=%ld\n", armci_me,myptr, *(void**)myptr,size); fflush(stdout);
 
507
       }
 
508
       /* store context info */
 
509
       ctx_shmem_global = (context_t*) ( ((int*)myptr)+offset );
 
510
       if(DEBUG_){
 
511
          printf("%d:armci_krmalloc_init_ctxshmem: shmid=%d off=%ld size=%ld\n", armci_me, ctx_shmem_global->shmid, ctx_shmem_global->shmoffset,
 
512
                 (long)ctx_shmem_global->shmsize);
 
513
          fflush(stdout);
 
514
       }
 
515
    }
 
516
}
 
517
 
 
518
void armci_shmem_init()
 
519
{
 
520
 
 
521
#ifdef ALLOC_MUNMAP
 
522
 
 
523
#if defined(QUADRICS) 
 
524
#   if (defined(__ia64__) || defined(__alpha)) && !defined(DECOSF) 
 
525
 
 
526
      /* this is to determine size of Elan Main memory allocator for munmap */
 
527
      long x;
 
528
      char *uval;
 
529
      uval = getenv("LIBELAN_ALLOC_SIZE");
 
530
      if(uval != NULL){
 
531
        sscanf(uval,"%ld",&x);
 
532
        if((x>80000000) && (x< 4*1024*1024*1024L)){ 
 
533
          max_alloc_munmap = (x>>20) - 72;
 
534
          if(DEBUG_){
 
535
            printf("%d: max_alloc_munmap is %ld\n",armci_me,max_alloc_munmap);
 
536
            fflush(stdout);
 
537
          }
 
538
        }
 
539
      }
 
540
 
 
541
      /* an alternative approach is to use MMAP area where we get
 
542
         the address from the Elan environment variable in qsnetlibs 1.4+  */
 
543
      uval = getenv("LIBELAN3_MMAPBASE");
 
544
      if(uval != NULL){
 
545
         sscanf(uval,"%p",&armci_elan_starting_address);
 
546
      }
 
547
 
 
548
#   endif
 
549
#   if defined(__ia64__)
 
550
       /* need aligment on 1MB boundary rather than the actual pagesize */
 
551
       pagesize = 1024*1024;
 
552
       logpagesize = 20;
 
553
#   else
 
554
       /* determine log2(pagesize) needed for address alignment */
 
555
       int tp=512;
 
556
       logpagesize = 9;
 
557
       pagesize = getpagesize();
 
558
       if(tp>pagesize)armci_die("armci_shmem_init:pagesize",pagesize);
 
559
 
 
560
       while(tp<pagesize){
 
561
         tp <<= 1;
 
562
         logpagesize++;
 
563
       }
 
564
       if(tp!=pagesize)armci_die("armci_shmem_init:pagesize pow 2",pagesize);
 
565
#   endif
 
566
 
 
567
   if(DEBUG_) {
 
568
     printf("page size =%d log=%d\n",pagesize,logpagesize); fflush(stdout); }
 
569
 
 
570
#endif
 
571
#endif
 
572
 
 
573
   if(armci_me == armci_master){
 
574
#if !defined(NO_SHMMAX_SEARCH) || defined(SHMMAX_SEARCH_NO_FORK)
 
575
#       ifdef SHMMAX_SEARCH_NO_FORK
 
576
          int x = armci_shmem_test_no_fork();
 
577
#       else
 
578
          int x = armci_child_shmem_init();
 
579
#       endif
 
580
 
 
581
        if(x<1)
 
582
          armci_die("no usable amount of shared memory available: only got \n",
 
583
          (int)LBOUND);
 
584
 
 
585
#       if defined(ALLOC_MUNMAP)
 
586
          /* cap down for special memory allocator unless ARMCI_DEFAULT_SHMMAX
 
587
             not set - the user knows what is doing*/
 
588
#         if !defined(REGION_ALLOC)
 
589
          if(!getenv("ARMCI_DEFAULT_SHMMAX"))
 
590
            if(x>max_alloc_munmap && !armci_elan_starting_address) x=max_alloc_munmap;
 
591
#         else
 
592
            x = 10; /* mb */
 
593
#         endif
 
594
#       endif
 
595
 
 
596
        if(DEBUG_){
 
597
           printf("%d:shmem_init: %d mbytes max segment size\n",armci_me,x);fflush(stdout);}
 
598
 
 
599
        MinShmem = (long)(x<<10); /* make sure it is in kb: mb <<10 */ 
 
600
        MaxShmem = MAX_REGIONS*MinShmem;
 
601
#       ifdef REPORT_SHMMAX
 
602
              printf("%d using x=%d SHMMAX=%ldKB\n", armci_me,x, MinShmem);
 
603
              fflush(stdout);
 
604
#       endif
 
605
#else
 
606
 
 
607
      /* nothing to do here - limits were given */
 
608
 
 
609
#endif
 
610
    }
 
611
 
 
612
    armci_krmalloc_init_ctxshmem();
 
613
    if(DEBUG_)printf("%d: out of shmem_init\n",armci_me);
 
614
}
 
615
 
 
616
void armci_set_shmem_limit_per_node(int nslaves)
 
617
{
 
618
     if (MaxShmem_per_core > 0) MaxShmem = nslaves*MaxShmem_per_core;
 
619
     if (MinShmem_per_core > 0) MinShmem = nslaves*MinShmem_per_core;
 
620
}
 
621
 
 
622
void armci_set_shmem_limit_per_core(unsigned long shmemlimit)
 
623
{
 
624
     MaxShmem_per_core = (shmemlimit + SHM_UNIT - 1)/SHM_UNIT;
 
625
     MinShmem_per_core = (shmemlimit + SHM_UNIT - 1)/SHM_UNIT;
 
626
}
 
627
 
 
628
/*\ application can reset the upper limit (bytes) for memory allocation
 
629
\*/
 
630
void armci_set_shmem_limit(unsigned long shmemlimit)
 
631
{
 
632
     unsigned long kbytes;
 
633
     kbytes = (shmemlimit + SHM_UNIT -1)/SHM_UNIT;
 
634
     if(MaxShmem > kbytes) MaxShmem = kbytes;
 
635
     if(MinShmem > kbytes) MinShmem = kbytes;
 
636
}
 
637
 
 
638
 
 
639
static void shmem_errmsg(size_t size)
 
640
{
 
641
long sz=(long)size;
 
642
    printf("******************* ARMCI INFO ************************\n");
 
643
    printf("The application attempted to allocate a shared memory segment ");
 
644
    printf("of %ld bytes in size. This might be in addition to segments ",sz);
 
645
    printf("that were allocated succesfully previously. ");
 
646
    printf("The current system configuration does not allow enough ");
 
647
    printf("shared memory to be allocated to the application.\n");
 
648
    printf("This is most often caused by:\n1) system parameter SHMMAX ");
 
649
    printf("(largest shared memory segment) being too small or\n");
 
650
    printf("2) insufficient swap space.\n");
 
651
    printf("Please ask your system administrator to verify if SHMMAX ");
 
652
    printf("matches the amount of memory needed by your application and ");
 
653
    printf("the system has sufficient amount of swap space. ");
 
654
    printf("Most UNIX systems can be easily reconfigured ");
 
655
    printf("to allow larger shared memory segments,\n");
 
656
    printf("see http://www.emsl.pnl.gov/docs/global/support.shtml\n");
 
657
    printf("In some cases, the problem might be caused by insufficient swap space.\n");
 
658
    printf("*******************************************************\n");
 
659
}
 
660
 
 
661
 
 
662
static struct shm_region_list{
 
663
   char     *addr;
 
664
   long     id;
 
665
   long     sz;
 
666
   long     attached;
 
667
}region_list[MAX_REGIONS];
 
668
static int alloc_regions=0;
 
669
static long occup_blocks=0;
 
670
 
 
671
/* Terminology
 
672
 *   region - actual piece of shared memory allocated from OS
 
673
 *   block  - a part of allocated shmem that is given to the requesting process
 
674
 */
 
675
 
 
676
 
 
677
static int last_allocated=-1;
 
678
 
 
679
 
 
680
unsigned long armci_max_region()
 
681
{
 
682
  return MinShmem;
 
683
}
 
684
 
 
685
 
 
686
int find_regions(char *addrp,  long* id, int *region)
 
687
{
 
688
int nreg, reg;
 
689
 
 
690
    if(last_allocated!=-1){
 
691
       reg=last_allocated;
 
692
       last_allocated = -1;
 
693
    } else{
 
694
       
 
695
       for(reg=-1,nreg=0;nreg<alloc_regions; nreg++)
 
696
       {
 
697
          if(addrp >= region_list[nreg].addr &&
 
698
             addrp < (region_list[nreg].addr + region_list[nreg].sz))
 
699
          {
 
700
             reg = nreg;
 
701
             break;
 
702
          }
 
703
       }
 
704
       
 
705
       if(reg == -1)
 
706
          armci_die("find_regions: failed to locate shared region", 0L);
 
707
    }
 
708
 
 
709
    *region = reg;
 
710
    *id = region_list[reg].id;
 
711
 
 
712
    return 1;
 
713
}
 
714
 
 
715
/* returns the shmem info based on the addr */
 
716
int armci_get_shmem_info(char *addrp,  int* shmid, long *shmoffset, 
 
717
                         size_t *shmsize) 
 
718
{    
 
719
    int region; long id;
 
720
 
 
721
    find_regions(addrp, &id, &region);
 
722
    *shmid     = id;
 
723
    *shmoffset = (long)(addrp - region_list[region].addr);
 
724
    *shmsize   = region_list[region].sz;
 
725
 
 
726
    return 1;
 
727
}
 
728
 
 
729
long armci_shm_reg_size(int i, long id)
 
730
{
 
731
     if(i<0 || i>= MAX_REGIONS)armci_die("armci_shmem_reg_size: bad i",i); 
 
732
     return region_list[i].sz;
 
733
}
 
734
 
 
735
void* armci_shm_reg_ptr(int i)
 
736
{
 
737
     if(i<0 || i>= MAX_REGIONS)armci_die("armci_shmem_reg_ptr: bad i",i); 
 
738
     return (void *)region_list[i].addr;
 
739
}
 
740
 
 
741
Header *armci_get_shmem_ptr(int shmid, long shmoffset, size_t shmsize) 
 
742
{
 
743
/* returns, address of the shared memory region based on shmid, offset.
 
744
 * (i.e. return_addr = stating address of shmid + offset)*/
 
745
    long idlist[SHMIDLEN];
 
746
    Header *p = NULL;
 
747
 
 
748
    idlist[1] = (long)shmid;
 
749
    idlist[0] = shmoffset;
 
750
    idlist[IDLOC+1] = shmsize; /* CHECK : idlist in CreateShmem????*/
 
751
 
 
752
    if(!(p=(Header*)Attach_Shared_Region(idlist+1, shmsize, idlist[0])))
 
753
       armci_die("kr_malloc:could not attach",(int)(p->s.shmsize>>10));
 
754
#if DEBUG_
 
755
    printf("%d: armci_get_shmem_ptr: %d %ld %ld %p\n",
 
756
           armci_me, idlist[1], idlist[0], shmsize, p);
 
757
    fflush(stdout);    
 
758
#endif
 
759
    return p;
 
760
}
 
761
 
 
762
 
 
763
char *Attach_Shared_Region(id, size, offset)
 
764
     long *id, offset, size;
 
765
{
 
766
int reg, found, shmflag=0;
 
767
static char *temp;
 
768
 
 
769
  if(alloc_regions>=MAX_REGIONS)
 
770
       armci_die("Attach_Shared_Region: to many regions ",0);
 
771
 
 
772
  if(DEBUG_){
 
773
      printf("%d:AttachSharedRegion %d:size=%ld id=%ld\n",
 
774
             armci_me, create_call++, size,*id);
 
775
      fflush(stdout);
 
776
  }
 
777
 
 
778
 
 
779
  /* under Linux we can get valid id=0 */
 
780
#ifndef LINUX
 
781
  if(!*id) armci_die("Attach_Shared_Region: shmem ID=0 ",(int)*id);
 
782
#endif
 
783
 
 
784
  /* first time needs to initialize region_list structure */
 
785
  if(!alloc_regions){
 
786
      for(reg=0;reg<MAX_REGIONS;reg++){
 
787
        region_list[reg].addr=(char*)0;
 
788
        region_list[reg].attached=0;
 
789
        region_list[reg].id=0;
 
790
      }
 
791
      MinShmem= id[SHMIDLEN-2];
 
792
      if(DEBUG2_){
 
793
         printf("%d:attach: allocation unit: %ldK\n",armci_me,MinShmem);
 
794
         fflush(stdout);
 
795
      }
 
796
  }
 
797
 
 
798
  /* search region_list for the current shmem id */
 
799
  for(found = 0, reg=0; reg < MAX_REGIONS;reg++)
 
800
      if((found=(region_list[reg].id == *id)))break;
 
801
 
 
802
  if(!found){
 
803
     reg = alloc_regions;
 
804
     region_list[reg].id =*id;
 
805
     alloc_regions++;
 
806
  }
 
807
 
 
808
  /* we need to use the actual shared memory segment not user req size */ 
 
809
  size = id[IDLOC];
 
810
 
 
811
  /* attach if not attached yet */
 
812
  if(!region_list[reg].attached){
 
813
 
 
814
#   ifdef ALLOC_MUNMAP
 
815
       char *pref_addr = alloc_munmap((size_t) (size));
 
816
#   else
 
817
       char *pref_addr = (char*)0;
 
818
#   endif
 
819
    if ( (long) (temp = shmat((int) *id, pref_addr, shmflag)) == -1L){
 
820
       fprintf(stderr,"%d:attach error:id=%ld off=%ld seg=%ld\n",armci_me,*id,offset,MinShmem);
 
821
       shmem_errmsg((size_t)MinShmem*1024);
 
822
       armci_die("Attach_Shared_Region:failed to attach to segment id=",(int)*id);
 
823
    }
 
824
    if(DEBUG_){
 
825
        printf("%d:attached: id=%d address=%p\n",armci_me,(int)*id, temp);
 
826
        fflush(stdout);
 
827
    }
 
828
    POST_ALLOC_CHECK(temp,size);
 
829
    region_list[reg].addr = temp; 
 
830
    region_list[reg].attached = 1;
 
831
    region_list[reg].sz= size;
 
832
    if(DEBUG_){
 
833
    printf("\n%d:%s:new memory region\n",armci_me,FUNCTION_NAME);fflush(stdout);
 
834
    }
 
835
 
 
836
  }
 
837
 
 
838
  if(STAMP)
 
839
  /* check stamp to make sure that we are attached in the right place */
 
840
  if(*((int*)(region_list[reg].addr+ offset))!= alloc_regions-1)
 
841
      armci_die("Attach_Shared_Region: wrong stamp value !", 
 
842
                *((int*)(region_list[reg].addr+ offset)));
 
843
  occup_blocks++;
 
844
  return (region_list[reg].addr+ offset);
 
845
}
 
846
 
 
847
#ifdef ALLOW_PIN
 
848
extern void armci_region_register_shm(void *start, long size);
 
849
#endif
 
850
 
 
851
/*\ allocates shmem, to be called by krmalloc that is called by process that
 
852
 *  creates shmem region
 
853
\*/
 
854
void *armci_allocate(long size)
 
855
{
 
856
char * temp;
 
857
int id,shmflag=0;
 
858
size_t sz = (size_t)size;
 
859
#ifdef ALLOC_MUNMAP
 
860
       char *pref_addr = alloc_munmap((size_t) (MinShmem*SHM_UNIT));
 
861
#else
 
862
       char *pref_addr = (char*)0;
 
863
#endif
 
864
#if defined(SGI_N32) && defined(SHM_SGI_ANYADDR)
 
865
  shmflag= SHM_SGI_ANYADDR;
 
866
#endif
 
867
 
 
868
    if(DEBUG1){
 
869
       printf("%d:allocate: Shmem allocate size %ld bytes\n",armci_me,size); 
 
870
       fflush(stdout);
 
871
    }
 
872
 
 
873
    if( alloc_regions >= MAX_REGIONS)
 
874
       armci_die("Create_Shared_Region:allocate:too many regions allocated ",0);
 
875
 
 
876
    last_allocated = alloc_regions;
 
877
 
 
878
#ifdef SHMMAX_SEARCH_NO_FORK
 
879
    if (ptr_search_no_fork){
 
880
        temp = ptr_search_no_fork;
 
881
        id   = id_search_no_fork;
 
882
        ptr_search_no_fork = (char*)0; /* do not look at it again */
 
883
    }else 
 
884
#endif
 
885
    {
 
886
       if ( (id = armci_shmget(sz,"armci_allocate")) < 0 ) {
 
887
          fprintf(stderr,"id=%d size=%ld\n",id, size);
 
888
          shmem_errmsg(sz);
 
889
          armci_die("allocate: failed to create shared region ",id);
 
890
       }
 
891
 
 
892
       if ( (long)( (temp = shmat(id, pref_addr, shmflag))) == -1L){
 
893
          char command[64];
 
894
          CLEANUP_CMD(command);
 
895
          if(system(command) == -1) 
 
896
            printf("Please clean shared memory (id=%d): see man ipcrm\n",id);
 
897
          armci_die("allocate: failed to attach to shared region id=",id);
 
898
       }
 
899
       if(DEBUG_){
 
900
         printf("%d:allocate:attach:id=%d paddr=%p size=%ld\n",armci_me,id,temp,size);
 
901
         fflush(stdout);
 
902
       }
 
903
#if 1
 
904
       /* delete segment id so that OS cleans it when all attached processes are gone */
 
905
       if(shmctl( id, IPC_RMID, (struct shmid_ds *)NULL))
 
906
          fprintf(stderr,"failed to remove shm id=%d\n",id);
 
907
#endif
 
908
 
 
909
    }
 
910
    POST_ALLOC_CHECK(temp,sz);
 
911
 
 
912
    region_list[alloc_regions].addr = temp;
 
913
    region_list[alloc_regions].id = id;
 
914
    region_list[alloc_regions].attached=1;
 
915
    region_list[alloc_regions].sz=sz;
 
916
    alloc_regions++;
 
917
 
 
918
    if(DEBUG2_){
 
919
      printf("%d:allocate:id=%d addr=%p size=%ld\n",armci_me,id,temp,size);
 
920
      fflush(stdout);
 
921
    }
 
922
 
 
923
    return (void*) (temp);
 
924
}
 
925
    
 
926
/******************** common code for the two versions *********************/
 
927
 
 
928
 
 
929
/*\ Allocate a block of shared memory - called by master process
 
930
\*/
 
931
char *Create_Shared_Region(long *id, long size, long *offset)
 
932
{
 
933
  char *temp;  
 
934
int  reg, refreg=0,nreg;
 
935
  
 
936
    if(alloc_regions>=MAX_REGIONS)
 
937
       armci_die("Create_Shared_Region: to many regions ",0);
 
938
 
 
939
    if(DEBUG_){
 
940
      printf("%d:CreateSharedRegion %d:size=%ld\n",armci_me,create_call++,size);
 
941
      fflush(stdout);
 
942
    }
 
943
 
 
944
    /*initialization: 1st allocation request */
 
945
    if(!alloc_regions){
 
946
       for(reg=0;reg<MAX_REGIONS;reg++){
 
947
          region_list[reg].addr=(char*)0;
 
948
          region_list[reg].attached=0;
 
949
          region_list[reg].id=0;
 
950
       }
 
951
       if(DEBUG_){
 
952
          printf("%d:1st CreateSharedRegion: allocation unit:%ldK,shmax:%ldK\n",
 
953
                 armci_me,MinShmem,MaxShmem);
 
954
          fflush(stdout);
 
955
       }
 
956
 
 
957
       kr_malloc_init(SHM_UNIT, (size_t)MinShmem, (size_t)MaxShmem, 
 
958
                      armci_allocate, 0, &ctx_shmem);
 
959
       ctx_shmem.ctx_type = KR_CTX_SHMEM;
 
960
       id[SHMIDLEN-2]=MinShmem;
 
961
    }
 
962
 
 
963
    if(!alloc_regions)  temp = kr_malloc((size_t)size, &ctx_shmem,0, NULL, NULL);
 
964
    else temp = kr_malloc((size_t)size, ctx_shmem_global,0,NULL,NULL);
 
965
 
 
966
    if(temp == (char*)0 )
 
967
       armci_die("CreateSharedRegion:kr_malloc failed KB=",(int)size>>10);
 
968
    
 
969
    if(!(nreg=find_regions(temp,id,&reg)))
 
970
        armci_die("CreateSharedRegion: allocation inconsitent",0);
 
971
 
 
972
#ifndef MULTIPLE_REGIONS
 
973
    refreg = reg;
 
974
#endif
 
975
 
 
976
    if(STAMP) *((int*)temp) = alloc_regions-1;
 
977
    *offset = (long) (temp - region_list[refreg].addr);
 
978
    id[IDLOC]=region_list[reg].sz; /* elan post check */
 
979
    occup_blocks++;
 
980
  
 
981
    if(DEBUG_){ 
 
982
      printf("%d:CreateShmReg:reg=%d id=%ld off=%ld ptr=%p adr=%p s=%d n=%d sz=%ld\n",
 
983
           armci_me,reg,region_list[reg].id,*offset,region_list[reg].addr,
 
984
           temp,(int)size,nreg,id[IDLOC]);
 
985
      fflush(stdout);
 
986
    }
 
987
 
 
988
    return temp;
 
989
}
 
990
 
 
991
 
 
992
 
 
993
/*\ only process that created shared region returns the pointer to kr_malloc 
 
994
\*/
 
995
void Free_Shmem_Ptr( id, size, addr)
 
996
     long id, size;
 
997
     char *addr;
 
998
{
 
999
  kr_free(addr, ctx_shmem_global);
 
1000
}
 
1001
 
 
1002
 
 
1003
void Delete_All_Regions()
 
1004
{
 
1005
int reg;
 
1006
int code=0;
 
1007
extern int armci_me;
 
1008
 
 
1009
  for(reg = 0; reg < MAX_REGIONS; reg++){
 
1010
    if(region_list[reg].addr != (char*)0){
 
1011
      code += shmctl((int)region_list[reg].id,IPC_RMID,(struct shmid_ds *)NULL);
 
1012
      region_list[reg].addr = (char*)0;
 
1013
      region_list[reg].attached = 0;
 
1014
      if(DEBUG_)
 
1015
         fprintf(stderr,"%d Delete_All_Regions id=%d code=%d\n",armci_me, 
 
1016
                (int)region_list[reg].id, code);
 
1017
    }
 
1018
  }
 
1019
}
 
1020
 
 
1021
 
 
1022
static int
 
1023
Semop(int semid,struct sembuf *opers,size_t nops) {
 
1024
      int ret;
 
1025
 
 
1026
      if((ret = semop(semid,opers,nops)) == -1) {
 
1027
         printf("%s: semop error performing %i operation(s) on semid %i.\n",Portals_ID(),(int) nops,semid);
 
1028
         switch(errno) {
 
1029
           case EFBIG:  printf(" semop errno=EFBIG.\n"); break;
 
1030
           case E2BIG:  printf(" semop errno=E2BIG.\n"); break;
 
1031
           case EINTR:  printf(" semop errno=EINTR.\n"); break;
 
1032
           case EINVAL: printf(" semop errno=EINVAL.\n"); break;
 
1033
           case EACCES: printf(" semop errno=EACCES.\n"); break;
 
1034
           case EAGAIN: printf(" semop errno=EAGAIN.\n"); break;
 
1035
           case ENOSPC: printf(" semop errno=ENOSPC.\n"); break;
 
1036
           case ERANGE: printf(" semop errno=ERANGE.\n"); break;
 
1037
           case EFAULT: printf(" semop errno=EFAULT.\n"); break;
 
1038
           default:
 
1039
              printf(" unusual semop errno=%d\n",errno); break;
 
1040
         }
 
1041
         armci_die("semaphore error",911);
 
1042
      }
 
1043
 
 
1044
      return ret;
 
1045
}
 
1046
 
 
1047
 
 
1048
int
 
1049
semaphoreOperation(int semid,int semnum,int semop) {
 
1050
      struct sembuf op;
 
1051
      op.sem_op  = semop;
 
1052
      op.sem_num = semnum;
 
1053
      op.sem_flg = 0;
 
1054
      return Semop(semid,&op,1);
 
1055
}
 
1056
 
 
1057
 
 
1058
void
 
1059
semaphoreAcquire(int semid, int semnum,int access) {
 
1060
     struct sembuf op;
 
1061
      op.sem_op = -access;
 
1062
      op.sem_num = semnum;
 
1063
      op.sem_flg = 0;
 
1064
      Semop(semid,&op,1);
 
1065
}
 
1066
 
 
1067
 
 
1068
void
 
1069
semaphoreRelease(int semid,int semnum,int access) {
 
1070
      struct sembuf op;
 
1071
      op.sem_op  = access;
 
1072
      op.sem_num = semnum;
 
1073
      op.sem_flg = 0;
 
1074
      Semop(semid,&op,1);
 
1075
}
 
1076
 
 
1077
#else
 
1078
 what are doing here ?
 
1079
#endif