~ubuntu-branches/ubuntu/saucy/nwchem/saucy

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/armci/tcgmsg/ipcv4.0/shmem.c

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2012-02-09 20:02:41 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120209200241-jgk03qfsphal4ug2
Tags: 6.1-1
* New upstream release.

[ Michael Banck ]
* debian/patches/02_makefile_flags.patch: Updated.
* debian/patches/02_makefile_flags.patch: Use internal blas and lapack code.
* debian/patches/02_makefile_flags.patch: Define GCC4 for LINUX and LINUX64
  (Closes: #632611 and LP: #791308).
* debian/control (Build-Depends): Added openssh-client.
* debian/rules (USE_SCALAPACK, SCALAPACK): Removed variables (Closes:
  #654658).
* debian/rules (LIBDIR, USE_MPIF4, ARMCI_NETWORK): New variables.
* debian/TODO: New file.
* debian/control (Build-Depends): Removed libblas-dev, liblapack-dev and
  libscalapack-mpi-dev.
* debian/patches/04_show_testsuite_diff_output.patch: New patch, shows the
  diff output for failed tests.
* debian/patches/series: Adjusted.
* debian/testsuite: Optionally run all tests if "all" is passed as option.
* debian/rules: Run debian/testsuite with "all" if DEB_BUILD_OPTIONS
  contains "checkall".

[ Daniel Leidert ]
* debian/control: Used wrap-and-sort. Added Vcs-Svn and Vcs-Browser fields.
  (Priority): Moved to extra according to policy section 2.5.
  (Standards-Version): Bumped to 3.9.2.
  (Description): Fixed a typo.
* debian/watch: Added.
* debian/patches/03_hurd-i386_define_path_max.patch: Added.
  - Define MAX_PATH if not defines to fix FTBFS on hurd.
* debian/patches/series: Adjusted.

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
/* $Header: /tmp/hpctools/ga/tcgmsg/ipcv4.0/shmem.c,v 1.13 2000-10-13 20:55:40 d3h325 Exp $ */
 
6
 
 
7
/*
 
8
  This stuff attempts to provide a simple interface to temporary shared
 
9
  memory regions, loosely modelled after that of Alliant Concentrix 5.0 
 
10
 
 
11
 
 
12
  Note that the input arguments switch between integers and pointers
 
13
  to integers depending on if they are modified on return.
 
14
 
 
15
 
 
16
  Create a shared region of at least size bytes, returning the actual size,
 
17
  the id associated with the region. The return value is a pointer to the
 
18
  the region. Any error is a hard fail.
 
19
 
 
20
  (char *) CreateSharedRegion((long *) id, (long *) size)
 
21
 
 
22
 
 
23
  Detach a process from a shared memory region. 0 is returned on success,
 
24
  -1 for failure. id, size, and addr must match exactly those items returned
 
25
  from CreateSharedRegion
 
26
 
 
27
  long DetachSharedRegion((long) id, (long) size, (char *) addr)
 
28
 
 
29
 
 
30
  Delete a shared region from the system. This has to be done on the SUN
 
31
  to remove it from the system. On the Alliant the shared region disappears
 
32
  when the last process dies or detaches. Returns 0 on success, -1 on error.
 
33
 
 
34
  long DeleteSharedRegion((long) id)
 
35
 
 
36
 
 
37
  Delete all the shared regions associated with this process.
 
38
 
 
39
  long DeleteSharedAll()
 
40
 
 
41
 
 
42
  Attach to a shared memory region of known id and size. Returns the
 
43
  address of the mapped memory. Size must exactly match the size returned
 
44
  from CreateSharedRegion (which in turn is the requested size rounded
 
45
  up to a multiple of 4096). Any error is a hard fail. 
 
46
 
 
47
  (char *) AttachSharedRegion((long) id, (long) size))
 
48
 
 
49
*/
 
50
 
 
51
extern void Error();
 
52
 
 
53
#ifdef ALLIANT
 
54
 
 
55
#include <stdio.h>
 
56
#include <sys/time.h>
 
57
 
 
58
extern char *valloc();
 
59
 
 
60
char *CreateSharedRegion(id, size)
 
61
     long *size, *id;
 
62
{
 
63
  struct timeval tp;
 
64
  struct timezone tzp;
 
65
  char *temp;
 
66
  int status;
 
67
 
 
68
  /* Have to round up to a multiple of page size before allocating
 
69
     on a page boundary */
 
70
 
 
71
  *size = ( (*size + 4095) / 4096 ) * 4096;
 
72
 
 
73
  if ( (temp = valloc((unsigned) *size)) == (char *) NULL)
 
74
    Error("CreateSharedRegion: failed in valloc", (long) 0);
 
75
 
 
76
  /* Now have to get a unique id ... try using time of day in centi-sec */
 
77
 
 
78
  if ( (status = gettimeofday(&tp, &tzp)) != 0)
 
79
    Error("CreateSharedRegion: error from gettimeofday", (long) status);
 
80
 
 
81
  *id = (tp.tv_sec + 10000*tp.tv_usec) & 0xffffff;
 
82
 
 
83
  /* Now make the region */
 
84
 
 
85
  if ( (status = create_shared_region(*id, temp, *size, 0)) != 0)
 
86
    Error("CreateSharedRegion: error from create_shared_region", (long) status);
 
87
 
 
88
  return temp;
 
89
}
 
90
 
 
91
long DetachSharedRegion( id, size, addr)
 
92
     long id, size;
 
93
     char *addr;
 
94
{
 
95
  return detach_shared_region( id, addr, size);
 
96
}
 
97
 
 
98
long DeleteSharedRegion(id)
 
99
     long id;
 
100
{
 
101
  return delete_shared_region(id);
 
102
}
 
103
 
 
104
char *AttachSharedRegion(id, size)
 
105
     long id, size;
 
106
{
 
107
  char *temp;
 
108
  int status;
 
109
 
 
110
  if (size !=  (((size + 4095) / 4096) * 4096))
 
111
    Error("AttachSharedRegion: input size is not multiple of 4096",
 
112
          (long) size);
 
113
 
 
114
  if ( (temp = valloc((unsigned) size)) == (char *) NULL)
 
115
    Error("AttachSharedRegion: failed in valloc", (long) 0);
 
116
 
 
117
  /* Now try to attach */
 
118
 
 
119
  if ( (status = attach_shared_region(id, temp, size)) != 0)
 
120
    Error("AttachSharedRegion: error from attach_shared_region",
 
121
          (long) status);
 
122
 
 
123
  return temp;
 
124
}
 
125
 
 
126
#endif
 
127
#if defined(SEQUENT) || defined(ENCORE) /* @**!ing SEQUENT and CRAY no elif */
 
128
 
 
129
#include <stdio.h>
 
130
 
 
131
#ifdef SEQUENT
 
132
#define SHMALLOC shmalloc
 
133
#define SHFREE   shfree
 
134
#endif
 
135
#ifdef ENCORE
 
136
#define SHMALLOC share_malloc
 
137
#define SHFREE   share_free
 
138
#endif
 
139
 
 
140
extern char *SHMALLOC();
 
141
extern int SHFREE();
 
142
 
 
143
#define MAX_ADDR 20
 
144
static int next_id = 0;              /* Keep track of id */
 
145
static char *shaddr[MAX_ADDR];       /* Keep track of addresses */
 
146
 
 
147
char *CreateSharedRegion(id, size)
 
148
     long *size, *id;
 
149
{
 
150
  char *temp;
 
151
 
 
152
  if (next_id >= MAX_ADDR)
 
153
        Error("CreateSharedRegion: too many shared regions", (long) next_id);
 
154
 
 
155
  if ( (temp = SHMALLOC((unsigned) *size)) == (char *) NULL)
 
156
    Error("CreateSharedRegion: failed in SHMALLOC", (long) *size);
 
157
 
 
158
  *id = next_id++;
 
159
  shaddr[*id] = temp;
 
160
 
 
161
  return temp;
 
162
}
 
163
 
 
164
/*ARGSUSED*/
 
165
long DetachSharedRegion( id, size, addr)
 
166
     long id, size;
 
167
     char *addr;
 
168
{
 
169
  /* This needs improving to make more robust */
 
170
  return SHFREE(addr);
 
171
}
 
172
 
 
173
long DeleteSharedRegion(id)
 
174
     long id;
 
175
{
 
176
  /* This needs improving to make more robust */
 
177
  return SHFREE(shaddr[id]);
 
178
}
 
179
 
 
180
/*ARGSUSED*/
 
181
char *AttachSharedRegion(id, size)
 
182
     long id, size;
 
183
{
 
184
  Error("AttachSharedRegion: cannot do this on SEQUENT or BALANCE", (long) -1);
 
185
}
 
186
 
 
187
 
 
188
#endif
 
189
   /* Bizarre sequent has sysv semaphores but proprietary shmem */
 
190
   /* Encore has sysv shmem but is limited to total of 16384bytes! */
 
191
#if defined(SYSV) && !defined(SEQUENT) && !defined(ENCORE)
 
192
 
 
193
#include <stdio.h>
 
194
#include <sys/types.h>
 
195
#include <sys/ipc.h>
 
196
#include <sys/shm.h>
 
197
 
 
198
char *CreateSharedRegion(id, size)
 
199
     long *size, *id;
 
200
{
 
201
  char *temp;
 
202
 
 
203
  /* Create the region */
 
204
 
 
205
  if ( (*id = shmget(IPC_PRIVATE, (int) *size, 
 
206
                     (int) (IPC_CREAT | 00600))) < 0 )
 
207
    Error("CreateSharedRegion: failed to create shared region", (long) *id);
 
208
 
 
209
  /* Attach to the region */
 
210
 
 
211
  if ( (long) (temp = shmat((int) *id, (char *) NULL, 0)) == -1L)
 
212
    Error("CreateSharedRegion: failed to attach to shared region", (long) 0);
 
213
 
 
214
  return temp;
 
215
}
 
216
 
 
217
/*ARGSUSED*/
 
218
long DetachSharedRegion( id, size, addr)
 
219
     long id, size;
 
220
     char *addr;
 
221
{
 
222
  return shmdt(addr);
 
223
}
 
224
 
 
225
long DeleteSharedRegion(id)
 
226
     long id;
 
227
{
 
228
  return shmctl((int) id, IPC_RMID, (struct shmid_ds *) NULL);
 
229
}
 
230
 
 
231
/*ARGSUSED*/
 
232
char *AttachSharedRegion(id, size)
 
233
     long id, size;
 
234
{
 
235
  char *temp;
 
236
 
 
237
  if ( (long) (temp = shmat((int) id, (char *) NULL, 0)) == -1L)
 
238
    Error("AttachSharedRegion: failed to attach to shared region", (long) 0);
 
239
 
 
240
  return temp;
 
241
}
 
242
 
 
243
#endif
 
244
#if (defined(CONVEX) || defined(APOLLO)) && !defined(HPUX) 
 
245
 
 
246
#include <stdio.h>
 
247
#include <sys/time.h>
 
248
#include <sys/types.h>
 
249
#include <sys/file.h>
 
250
#include <sys/mman.h>
 
251
 
 
252
extern char *strdup();
 
253
extern char *mktemp();
 
254
 
 
255
#define MAX_ID 20
 
256
static struct id_list_struct {
 
257
  char *addr;                      /* pointer to shmem region */
 
258
  unsigned size;                   /* size of region */
 
259
  char *filename;                  /* associated file name */
 
260
  int fd;                          /*            file descriptor */
 
261
  int status;                      /* = 1 if in use */
 
262
} id_list[MAX_ID];
 
263
 
 
264
static int next_id = 0;
 
265
static char template[] = "/tmp/SHMEM.XXXXXX";
 
266
 
 
267
char *CreateSharedRegion(id, size)
 
268
     long *size, *id;
 
269
{
 
270
  char *temp;
 
271
 
 
272
  if (next_id == MAX_ID)
 
273
    Error("CreateSharedRegion: MAX_ID exceeded ", MAX_ID);
 
274
  *id = next_id;
 
275
 
 
276
#ifdef APOLLO
 
277
  id_list[*id].fd = -1;
 
278
#else
 
279
  if ( (temp = strdup(template)) == (char *) NULL)
 
280
    Error("CreateSharedRegion: failed to get space for filename", 0);
 
281
 
 
282
/* Generate scratch file to identify region ... need to know this
 
283
   name to attach to the region so need to establish some policy
 
284
   before AttachtoSharedRegion can work */
 
285
 
 
286
  id_list[*id].filename = mktemp(temp);
 
287
  if ( (id_list[*id].fd = open(id_list[*id].filename, 
 
288
                                   O_RDWR|O_CREAT, 0666)) < 0)
 
289
    Error("CreateSharedRegion: failed to open temporary file",0);
 
290
#endif
 
291
 
 
292
  id_list[*id].addr = mmap((caddr_t) 0, (unsigned *) size, 
 
293
                           PROT_READ|PROT_WRITE, 
 
294
                           MAP_ANON|MAP_SHARED, id_list[*id].fd, 0);
 
295
#ifdef APOLLO
 
296
  if (id_list[*id].addr == (char *) 0)
 
297
    Error("CreateSharedRegion: mmap failed",-1);
 
298
#else
 
299
  if (id_list[*id].addr == (char *) -1)
 
300
    Error("CreateSharedRegion: mmap failed",-1);
 
301
#endif
 
302
 
 
303
  id_list[*id].size = *size;
 
304
  id_list[*id].status = 1;
 
305
 
 
306
  next_id++;
 
307
  return id_list[*id].addr;
 
308
}
 
309
 
 
310
/*ARGSUSED*/
 
311
long DetachSharedRegion( id, size, addr)
 
312
     long id, size;
 
313
     char *addr;
 
314
{
 
315
 if ( (id < 0) || (id > next_id))
 
316
   return (long) -1;
 
317
 
 
318
 if (id_list[id].status != 1)
 
319
   return (long) -1;
 
320
 
 
321
 id_list[id].status = 0;
 
322
 
 
323
 return (long) munmap(id_list[id].addr, 0);
 
324
}
 
325
 
 
326
long DeleteSharedRegion(id)
 
327
     long id;
 
328
{
 
329
 if ( (id < 0) || (id > next_id) )
 
330
   return (long) -1;
 
331
 
 
332
 if (id_list[id].status != 1)
 
333
   return (long) -1;
 
334
 
 
335
  (void) DetachSharedRegion(id, 0, (char *) 0);
 
336
 
 
337
  if (id_list[id].fd >= 0) {
 
338
    (void) close(id_list[id].fd);
 
339
    (void) unlink(id_list[id].filename);
 
340
  }
 
341
 
 
342
  return (long) 0;
 
343
}
 
344
 
 
345
/*ARGSUSED*/
 
346
char *AttachSharedRegion(id, size)
 
347
     long id, size;
 
348
{
 
349
  Error("AttachSharedRegion: need mods for this to work on CONVEX",
 
350
        (long) -1);
 
351
}
 
352
 
 
353
long DeleteSharedAll()
 
354
{
 
355
  long id;
 
356
  long status = 0;
 
357
 
 
358
  for (id=0; id<next_id; id++)
 
359
    if (id_list[id].status == 1)
 
360
      status += DeleteSharedRegion(id);
 
361
 
 
362
  if (status)
 
363
    return (long) -1;
 
364
  else
 
365
    return (long) 0;
 
366
}
 
367
 
 
368
#endif