24 #if defined(INTERCEPT_ALLOC) 30 typedef long long int ll_t;
31 typedef unsigned long long int u_ll_t;
35 #define FNECSX_MAXDIM 7 45 #define FNECSX_NKEYS 3 46 #define FNECSX_KEY_LO 0 47 #define FNECSX_KEY_HI 1 48 #define FNECSX_KEY_ST 2 54 ll_t s[FNECSX_MAXDIM][FNECSX_NKEYS];
72 extern void necsx_trbk_fl_(
const char *msg,
const char *filename,
int *lineno,
73 int msglen,
int filenamelen);
74 #define ERROR_MSG(msg) { \ 75 int lineno = __LINE__; necsx_trbk_fl_(msg, __FILE__, &lineno, strlen(msg), sizeof(__FILE__)-1); } 78 #undef INTERCEPT_ALLOC 82 #if !defined(INTERCEPT_ALLOC) 103 for (j=0; j<
n; j++) p4[j] = tmp;
111 for (j=0; j<
n; j++) p8[j] = tmp;
120 env = getenv(
"EC_PRTDESC");
130 env = getenv(
"EC_INITHEAP");
132 int len = strlen(env);
133 if (strcasecmp(env,
"zero") == 0 || strcasecmp(env,
"0") == 0) {
137 else if (strcasecmp(env,
"nan") == 0) {
140 if (
ec_prtdesc) fprintf(stderr,
"EC_INITHEAP='%s' => ec_initheap = %d : value = 0x%x (%u,%d)\n",
143 else if (len >= 2 && env[0] ==
'0' && (env[1] ==
'x' || env[1] ==
'X')) {
147 if (
ec_prtdesc) fprintf(stderr,
"EC_INITHEAP='%s' => ec_initheap = %d : value = 0x%x (%u,%d)\n",
150 else if (len > 10 && len <= 18) {
153 if (
ec_prtdesc) fprintf(stderr,
"EC_INITHEAP='%s' => ec_initheap = %d : value = 0x%llx (%llu,%lld)\n",
169 env = getenv(
"EC_MALLOC");
183 const int *stat,
ll_t elsize_in)
191 int ndims = d->ndims;
192 ll_t elsize = d->s[0][FNECSX_KEY_ST];
195 ll_t nsave[FNECSX_MAXDIM];
196 #pragma cdir altcode,loopcnt=FNECSX_MAXDIM 197 for (j=0; j<ndims; j++) {
198 ll_t n = d->s[j][FNECSX_KEY_HI] - d->s[j][FNECSX_KEY_LO] + 1;
202 if (((ntot/2)*2) != ntot) ntot++;
203 total_bytes = ntot * elsize + 1;
204 fprintf(fp,
"=== %s : desc = 0x%llx [%lld] : arg1 = %lld, stat (addr) = 0x%llx\n",s,d,d,arg1,stat);
205 fprintf(fp,
"p = 0x%llx [%lld] : status = %d, ndims = %d, elsize's = (%lld, %lld), total = %lld\n",
206 d->p, d->p, d->status, ndims, elsize, elsize_in, total_bytes);
207 for (j=0; j<ndims; j++) {
209 fprintf(fp,
"[dim#%d] : lo = %lld, hi = %lld (n=%lld), stride = %lld\n",
210 j+1, d->s[j][FNECSX_KEY_LO], d->s[j][FNECSX_KEY_HI], n,
211 d->s[j][FNECSX_KEY_ST]);
215 u_ll_t adjsize = d->p[-2];
217 fprintf(fp,
"\tdummy = %llu\n",dummy);
218 fprintf(fp,
"\tadjsize (bytes) = %llu\n",adjsize);
219 fprintf(fp,
"\tDr.Hook keyptr = 0x%llx [%llu]\n",keyptr,keyptr);
228 return (d && d->p && (d->status == 3 || d->status == 1)) ? 1 : 0;
234 const int istat_offset = 193;
236 const char *errmsg[2] = {
237 "Value of allocate-object must not be currently allocated array in ALLOCATE.",
238 "Could not allocate in ALLOCATE." 240 if (stat && stat == (
int *)0
x1) stat = NULL;
242 if (d && (arg1 == 3 || arg1 == 2)) {
246 int ndims = d->ndims;
251 ll_t nsave[FNECSX_MAXDIM];
252 #pragma cdir altcode,loopcnt=FNECSX_MAXDIM 253 for (j=0; j<ndims; j++) {
254 ll_t n = d->s[j][FNECSX_KEY_HI] - d->s[j][FNECSX_KEY_LO] + 1;
258 if (((ntot/2)*2) != ntot) ntot++;
259 total_bytes = ntot * elsize + 1;
266 vptr = calloc(total_bytes,1);
274 vptr = malloc(total_bytes);
279 ll_t n = total_bytes/4;
284 ll_t n = total_bytes/8;
292 d->status = (arg1 == 3) ? 3 : 1;
293 d->s[0][FNECSX_KEY_ST] = elsize;
295 #pragma cdir altcode,loopcnt=FNECSX_MAXDIM 296 for (j=1; j<ndims; j++) {
297 d->s[j][FNECSX_KEY_ST] = nsave[j] * d->s[j-1][FNECSX_KEY_ST];
309 if (istat != 0 && !stat) {
310 const char *msg = errmsg[istat-istat_offset];
311 fprintf(stderr,
"***Error#%d: %s\n",istat,msg);
312 prtdesc(arg1, stderr,
"f_alloc", d, stat, elsize);
317 if (stat) *stat = istat;
324 if (stat && stat == (
ll_t *)0
x1) stat = NULL;
325 f_alloc(arg1, d, stat ? &istat : NULL, elsize);
326 if (stat) *stat = istat;
332 const int istat_offset = 195;
334 const char *errmsg[2] = {
335 "Value of allocate-object must not be disassociated pointer/not allocated array in DEALLOCATE.",
336 "Illegal value of allocate-object in DEALLOCATE." 338 if (stat && stat == (
int *)0
x1) stat = NULL;
340 if (d && ((arg1 | d->status) == 3)) {
342 int ndims = d->ndims;
353 #pragma cdir altcode,loopcnt=FNECSX_MAXDIM 354 for (j=0; j<ndims; j++) {
355 d->s[j][FNECSX_KEY_ST] = 0;
366 if (istat != 0 && !stat) {
367 const char *msg = errmsg[istat-istat_offset];
368 fprintf(stderr,
"***Error#%d: %s\n",istat,msg);
369 prtdesc(arg1, stderr,
"f_deallc", d, stat, -1);
374 if (stat) *stat = istat;
381 if (stat && stat == (
ll_t *)0
x1) stat = NULL;
382 f_deallc(arg1, d, stat ? &istat : NULL);
383 if (stat) *stat = istat;
void necsx_trbk_fl_(const char *msg, const char *filename, int *lineno, int msglen, int filenamelen)
static void init8(u_ll_t p8[], ll_t n)
void f_alloc(ll_t arg1, desc_t *d, int *stat, ll_t elsize)
void f_deallcl(ll_t arg1, desc_t *d, ll_t *stat)
static void prtdesc(ll_t arg1, FILE *fp, const char *s, const desc_t *d, const int *stat, ll_t elsize_in)
unsigned long long int u_ll_t
void f_deallc(ll_t arg1, desc_t *d, int *stat)
ll_t fy_sallocd(desc_t *d)
void f_allocl(ll_t arg1, desc_t *d, ll_t *stat, ll_t elsize)
static void init4(unsigned int p4[], ll_t n)
void * EC_calloc(long long int nelem, long long int elsize)
void * EC_malloc(long long int size)
unsigned long long int u_ll_t
static u_ll_t ec_initval8
static unsigned int ec_initval4