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

« back to all changes in this revision

Viewing changes to src/tools/ga-5-2/armci/tcgmsg/ipcv4.0/sema_alliant.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
/*
 
6
  These routines simplify the interface to semaphores for use in mutual
 
7
  exclusion and queuing. Hopefully I can also make this portable.
 
8
 
 
9
  An external routine Error is assumed which is called upon an error
 
10
  and tidies up by calling SemSetDestroyAll.
 
11
 
 
12
  In most cases errors cause an internal hard failure (by calling Error).
 
13
 
 
14
  1) make an array of n_sem semaphores, returning the id associated
 
15
     with the entire set. All the semaphore values are initialized to value
 
16
     which should be a positve integer (queuing) or 0 (synchronization).
 
17
     The semaphores in the set are indexed from 0 to n_sem-1.
 
18
 
 
19
     long SemSetCreate(long n_sem, long value)
 
20
 
 
21
  2) Decrement and test the value associated with the semaphore specified by 
 
22
     (sem_set_id, sem_num). In effect this:
 
23
 
 
24
     if (value >= 0) {
 
25
        continue execution
 
26
     }
 
27
     else {
 
28
        wait in queue for the semaphore
 
29
     }
 
30
     decrement value
 
31
 
 
32
     void SemWait(long sem_set_id, long sem_num)
 
33
 
 
34
  3) Increment the value associated with the semaphore specified by
 
35
     (sem_set_id, sem_num). If value <= 0 (i.e. there are processes
 
36
     in the queue) this releases the next process.
 
37
 
 
38
     void SemPost(long sem_set_id, long sem_num)
 
39
     
 
40
  4) Return the current value associated with the semaphore sepcified by
 
41
     (sem_set_id, sem_num).
 
42
 
 
43
     long SemValue(long sem_set_id, long sem_num)
 
44
 
 
45
  5) Destroy the set of semaphores. Any other processes that are accessing
 
46
     or try to access the semaphore set should get an error.
 
47
     On the SUN (all system V machines?) the semaphore sets should
 
48
     be destroyed explicitly before the final process exits.
 
49
     0 is returned if OK. -1 implies an error.
 
50
 
 
51
     long SemSetDestroy(long sem_set_id)
 
52
 
 
53
  6) Destroy all the semaphore sets that are known about. This is really
 
54
     meant for an error routine to call to try and tidy up. Though all
 
55
     applications could call it before the last process exits.
 
56
     0 is returned if OK. -1 implies an error.
 
57
 
 
58
     long SemSetDestroyAll()
 
59
*/
 
60
 
 
61
extern void Error();
 
62
 
 
63
/*************************************************************
 
64
    Alliant Concentrix 5.0 and Concentrix FX/2800
 
65
 *************************************************************/
 
66
 
 
67
/* This is very specific to the Alliant. */
 
68
 
 
69
#include <sys/rtsem.h>
 
70
#include <sys/errno.h>
 
71
 
 
72
extern int errno;
 
73
 
 
74
/* On the alliant semaphores are handed out one at a time rather than
 
75
   in sets, so have to maintain sets manually */
 
76
 
 
77
#define MAX_SEM_SETS 20
 
78
#define MAX_N_SEM 128
 
79
 
 
80
static struct sem_set_list_struct {
 
81
  int id[MAX_N_SEM];                       /* alliant semaphore id */
 
82
  int n_sem;                               /* no. of semaphores in set */
 
83
} sem_set_list[MAX_SEM_SETS];
 
84
 
 
85
static int num_sem_set = 0;
 
86
 
 
87
 
 
88
void InitSemSetList()
 
89
/* Initialise sem_set_list */
 
90
{
 
91
  int i, j;
 
92
  
 
93
  for (i=0; i<MAX_SEM_SETS; i++) {
 
94
    sem_set_list[i].n_sem = 0;
 
95
    for (j=0; j<MAX_N_SEM; j++)
 
96
      sem_set_list[i].id[j] = -1;
 
97
  }
 
98
}
 
99
 
 
100
long SemSetCreate(n_sem, value)
 
101
     long n_sem;
 
102
     long value;
 
103
{
 
104
  int semid, i, j;
 
105
 
 
106
  /* Check for errors and initialise data if first entry */
 
107
 
 
108
  if ( (n_sem <= 0) || (n_sem >= MAX_N_SEM) )
 
109
    Error("SemSetCreate: n_sem has invalid value", (long) n_sem);
 
110
 
 
111
  if (num_sem_set == 0)
 
112
    InitSemSetList();
 
113
  else if (num_sem_set >= MAX_SEM_SETS)
 
114
    Error("SemSetCreate: Exceeded man no. of semaphore sets",
 
115
          (long) num_sem_set);
 
116
 
 
117
  /* Find first empty slot in sem_set_list */
 
118
 
 
119
  for (i=0; i < MAX_SEM_SETS; i++) 
 
120
    if (sem_set_list[i].n_sem == 0)
 
121
      break;
 
122
 
 
123
  if (i == MAX_SEM_SETS)
 
124
    Error("SemSetCreate: internal error puting semid in list", (long) i);
 
125
 
 
126
  /* Actually make the semaphore set */
 
127
 
 
128
  for (j=0; j<n_sem; j++) {
 
129
    if ( (semid = sem_create(value, value, SEMQUE_FIFO, 0)) < 0)
 
130
      Error("SemSetCreate: failed to create semaphore", (long) j);
 
131
    sem_set_list[i].id[j] = semid;
 
132
  }
 
133
 
 
134
  num_sem_set++;
 
135
  
 
136
  return i;
 
137
}
 
138
 
 
139
void SemWait(sem_set_id, sem_num)
 
140
     long sem_set_id;
 
141
     long sem_num;
 
142
{
 
143
interrupted:
 
144
  if (sem_wait(sem_set_list[sem_set_id].id[sem_num]) < 0) {
 
145
    if (errno == EINTR)
 
146
      goto interrupted;   /* got zapped by a signal ... try again */
 
147
    else
 
148
      Error("SemWait: error from sem_wait", (long) -1);
 
149
  }
 
150
}
 
151
 
 
152
void SemPost(sem_set_id, sem_num)
 
153
     long sem_set_id;
 
154
     long sem_num;
 
155
{
 
156
  if (sem_post(sem_set_list[sem_set_id].id[sem_num]) < 0)
 
157
    Error("SemPost: error from sem_post", (long) -1);
 
158
}
 
159
 
 
160
long SemValue(sem_set_id, sem_num)
 
161
     long sem_set_id;
 
162
     long sem_num;
 
163
{
 
164
  SEM_INFO info;
 
165
 
 
166
  if (sem_info(sem_set_list[sem_set_id].id[sem_num], &info, sizeof info) < 0)
 
167
    Error("SemValue: error from sem_info", (long) -1);
 
168
 
 
169
  return info.curval;
 
170
}
 
171
 
 
172
long SemSetDestroy(sem_set_id)
 
173
     long sem_set_id;
 
174
{
 
175
  int status=0, i;
 
176
 
 
177
  /* Close each semaphore in the set */
 
178
 
 
179
  for (i=0; i<sem_set_list[sem_set_id].n_sem; i++) {
 
180
    status += sem_destroy(sem_set_list[sem_set_id].id[i]);
 
181
    sem_set_list[sem_set_id].id[i] = -1;
 
182
  }
 
183
 
 
184
  sem_set_list[sem_set_id].n_sem = 0;
 
185
 
 
186
  num_sem_set--;
 
187
 
 
188
  if (status)
 
189
    status = -1;
 
190
 
 
191
  return (long) status;
 
192
}
 
193
  
 
194
long SemSetDestroyAll()
 
195
{
 
196
  int i, status=0;
 
197
 
 
198
  for (i=0; i<MAX_SEM_SETS; i++)
 
199
    if (sem_set_list[i].n_sem)
 
200
      status += SemSetDestroy(i);
 
201
 
 
202
  if (status)
 
203
    status = -1;
 
204
 
 
205
  return (long) status;
 
206
}