/[ascend]/trunk/base/generic/compiler/parpend.c
ViewVC logotype

Contents of /trunk/base/generic/compiler/parpend.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 669 - (show annotations) (download) (as text)
Wed Jun 21 07:00:45 2006 UTC (13 years, 2 months ago) by johnpye
File MIME type: text/x-csrc
File size: 3391 byte(s)
Merged changes from DAE branch (revisions 702 to 819) back into trunk.
This adds the Integration API to the ASCEND solver (in base/generic).
Also provides pre-alpha support for 'IDA' from the SUNDIALS suite, a DAE solver.
Many other minor code clean-ups, including adoption of new 'ASC_NEW' and friends (to replace 'ascmalloc')
Added some very sketchy stuff providing 'DIFF(...)' syntax, although it is anticipated that this will be removed.
1 /*
2 * parpend.c
3 * by Ben Allan
4 * Jan 5, 1998
5 * Part of ASCEND
6 * Version: $Revision: 1.3 $
7 * Version control file: $RCSfile: parpend.c,v $
8 * Date last modified: $Date: 1998/06/16 16:38:45 $
9 * Last modified by: $Author: mthomas $
10 *
11 * This file is part of the Ascend Language Interpreter.
12 *
13 * Copyright (C) 1998 Carnegie Mellon University
14 *
15 * The Ascend Language Interpreter is free software; you can
16 * redistribute it and/or modify it under the terms of the GNU
17 * General Public License as published by the Free Software
18 * Foundation; either version 2 of the License, or (at your option)
19 * any later version.
20 *
21 * The Ascend Language Interpreter is distributed in hope that it
22 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with the program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check
29 * the file named COPYING.
30 */
31
32 #include <stdarg.h>
33 #include <utilities/ascConfig.h>
34 #include <utilities/ascMalloc.h>
35 #include <utilities/ascPanic.h>
36 #include <general/pool.h>
37 #include "fractions.h"
38 #include "compiler.h"
39 #include "dimen.h"
40 #include "expr_types.h"
41 #include "stattypes.h"
42 #include "instance_enum.h"
43 #include "parpend.h"
44
45
46 static pool_store_t g_ppe_pool = NULL;
47 /* global for our memory manager */
48 /* aim for small chunks including malloc overhead because max use
49 * is not large.
50 */
51 #define PPE_LEN 3
52 #if (SIZEOF_VOID_P == 8)
53 #define PPE_WID 4
54 #else
55 #define PPE_WID 4
56 #endif
57 /* retune rpwid if the size of struct name changes */
58 #define PPE_ELT_SIZE (sizeof(struct parpendingentry))
59 #define PPE_MORE_ELTS 1
60 /*
61 * Number of slots filled if more elements needed.
62 * So if the pool grows, it grows by PPE_MORE_ELTS*PPE_WID elements at a time.
63 */
64 #define PPE_MORE_BARS 50
65 /* This is the number of pool bar slots to add during expansion.
66 not all the slots will be filled immediately. */
67
68 #define PPMALLOC ((struct parpendingentry *)(pool_get_element(g_ppe_pool)))
69 /* get a token. Token is the size of the struct struct parpendingentry */
70 #define PPFREE(p) (pool_free_element(g_ppe_pool,((void *)p)))
71 /* return a struct parpendingentry */
72
73 struct parpendingentry *CreatePPE(void)
74 {
75 struct parpendingentry *new;
76 new = PPMALLOC;
77 if (new ==NULL) {
78 Asc_Panic(2, NULL, "malloc fail in CreatePPE. Bye!\n");
79 }
80 return new;
81 }
82
83 void DestroyPPE(struct parpendingentry *old)
84 {
85 PPFREE(old);
86 }
87
88 /* This function is called at compiler startup time and destroy at shutdown. */
89 void ppe_init_pool(void) {
90 if (g_ppe_pool != NULL ) {
91 Asc_Panic(2, NULL, "ERROR: ppe_init_pool called twice.\n");
92 }
93 g_ppe_pool = pool_create_store(PPE_LEN, PPE_WID, PPE_ELT_SIZE,
94 PPE_MORE_ELTS, PPE_MORE_BARS);
95 if (g_ppe_pool == NULL) {
96 Asc_Panic(2, NULL, "ERROR: ppe_init_pool unable to allocate pool.\n");
97 }
98 }
99
100 void ppe_destroy_pool(void) {
101 if (g_ppe_pool==NULL) return;
102 pool_clear_store(g_ppe_pool);
103 pool_destroy_store(g_ppe_pool);
104 g_ppe_pool = NULL;
105 }
106
107 void ppe_report_pool(void)
108 {
109 if (g_ppe_pool==NULL) {
110 FPRINTF(ASCERR,"parpendingentrysPool is empty\n");
111 }
112 FPRINTF(ASCERR,"parpendingentrysPool ");
113 pool_print_store(ASCERR,g_ppe_pool,0);
114 }
115

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22