Polish multicore code
[IRC.git] / Robust / src / Runtime / bamboo / multicoremem.c
1 #ifdef MULTICORE
2 #include "runtime_arch.h"
3 #include "multicoreruntime.h"
4
5 extern int corenum;
6
7 #ifdef MULTICORE_GC
8 #include "multicorehelper.h"
9
10 #ifdef SMEMF
11 #define NUM_CORES2TEST 5
12 #ifdef GC_1
13 int core2test[1][NUM_CORES2TEST] = {
14   {0, -1, -1, -1, -1}
15 };
16 #elif defined GC_56
17 int core2test[56][NUM_CORES2TEST] = {
18   { 0, -1,  7, -1,  1}, { 1, -1,  8,  0,  2}, { 2, -1,  9,  1,  3},
19   { 3, -1, 10,  2,  4}, { 4, -1, 11,  3,  5}, { 5, -1, 12,  4,  6},
20   { 6, -1, 13,  5, -1}, { 7,  0, 14, -1,  8}, { 8,  1, 15,  7,  9},
21   { 9,  2, 16,  8, 10}, {10,  3, 17,  9, 11}, {11,  4, 18, 10, 12},
22   {12,  5, 19, 11, 13}, {13,  6, 20, 12, -1}, {14,  7, 21, -1, 15},
23   {15,  8, 22, 14, 16}, {16,  9, 23, 15, 17}, {17, 10, 24, 16, 18},
24   {18, 11, 25, 17, 19}, {19, 12, 26, 18, 20}, {20, 13, 27, 19, -1},
25   {21, 14, 28, -1, 22}, {22, 15, 29, 21, 23}, {23, 16, 30, 22, 24},
26   {24, 17, 31, 23, 25}, {25, 18, 32, 24, 26}, {26, 19, 33, 25, 27},
27   {27, 20, 34, 26, -1}, {28, 21, 35, -1, 29}, {29, 22, 36, 28, 30},
28   {30, 23, 37, 29, 31}, {31, 24, 38, 30, 32}, {32, 25, 39, 31, 33},
29   {33, 26, 40, 32, 34}, {34, 27, 41, 33, -1}, {35, 28, 42, -1, 36},
30   {36, 29, 43, 35, 37}, {37, 30, 44, 36, 38}, {38, 31, 45, 37, 39},
31   {39, 32, 46, 38, 40}, {40, 33, 47, 39, 41}, {41, 34, 48, 40, -1},
32   {42, 35, 49, -1, 43}, {43, 36, 50, 42, 44}, {44, 37, 51, 43, 45},
33   {45, 38, 52, 44, 46}, {46, 39, 53, 45, 47}, {47, 40, 54, 46, 48},
34   {48, 41, 55, 47, -1}, {49, 42, -1, -1, 50}, {50, 43, -1, 49, 51},
35   {51, 44, -1, 50, 52}, {52, 45, -1, 51, 53}, {53, 46, -1, 52, 54},
36   {54, 47, -1, 53, 55}, {55, 48, -1, 54, -1}
37 };
38 #elif defined GC_62
39 int core2test[62][NUM_CORES2TEST] = {
40   { 0, -1,  6, -1,  1}, { 1, -1,  7,  0,  2}, { 2, -1,  8,  1,  3},
41   { 3, -1,  9,  2,  4}, { 4, -1, 10,  3,  5}, { 5, -1, 11,  4, -1},
42   { 6,  0, 14, -1,  7}, { 7,  1, 15,  6,  8}, { 8,  2, 16,  7,  9},
43   { 9,  3, 17,  8, 10}, {10,  4, 18,  9, 11}, {11,  5, 19, 10, 12},
44   {12, -1, 20, 11, 13}, {13, -1, 21, 12, -1}, {14,  6, 22, -1, 15},
45   {15,  7, 23, 14, 16}, {16,  8, 24, 15, 17}, {17,  9, 25, 16, 18},
46   {18, 10, 26, 17, 19}, {19, 11, 27, 18, 20}, {20, 12, 28, 19, 21},
47   {21, 13, 29, 28, -1}, {22, 14, 30, -1, 23}, {23, 15, 31, 22, 24},
48   {24, 16, 32, 23, 25}, {25, 17, 33, 24, 26}, {26, 18, 34, 25, 27},
49   {27, 19, 35, 26, 28}, {28, 20, 36, 27, 29}, {29, 21, 37, 28, -1},
50   {30, 22, 38, -1, 31}, {31, 23, 39, 30, 32}, {32, 24, 40, 31, 33},
51   {33, 25, 41, 32, 34}, {34, 26, 42, 33, 35}, {35, 27, 43, 34, 36},
52   {36, 28, 44, 35, 37}, {37, 29, 45, 36, -1}, {38, 30, 46, -1, 39},
53   {39, 31, 47, 38, 40}, {40, 32, 48, 39, 41}, {41, 33, 49, 40, 42},
54   {42, 34, 50, 41, 43}, {43, 35, 51, 42, 44}, {44, 36, 52, 43, 45},
55   {45, 37, 53, 44, -1}, {46, 38, 54, -1, 47}, {47, 39, 55, 46, 48},
56   {48, 40, 56, 47, 49}, {49, 41, 57, 48, 50}, {50, 42, 58, 49, 51},
57   {51, 43, 59, 50, 52}, {52, 44, 60, 51, 53}, {53, 45, 61, 52, -1},
58   {54, 46, -1, -1, 55}, {55, 47, -1, 54, 56}, {56, 48, -1, 55, 57},
59   {57, 49, -1, 56, 59}, {58, 50, -1, 57, 59}, {59, 51, -1, 58, 60},
60   {60, 52, -1, 59, 61}, {61, 53, -1, 60, -1}
61 };
62 #endif // GC_1
63 #elif defined SMEMM
64 unsigned int gcmem_mixed_threshold = 0;
65 unsigned int gcmem_mixed_usedmem = 0;
66 #define NUM_CORES2TEST 13
67 #ifdef GC_1
68 int core2test[1][NUM_CORES2TEST] = {
69   {0, -1, -1, -1, -1, -1, -1, -1, -1}
70 };
71 #elif defined GC_2
72 int core2test[2][NUM_CORES2TEST] = {
73   { 0, -1, -1, -1,  1, -1, -1, -1, -1, -1, -1, -1, -1}, 
74   { 1, -1,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1} 
75 };
76 #elif defined GC_4
77 int core2test[4][NUM_CORES2TEST] = {
78   { 0, -1, -1,  2,  1, -1, -1, -1, -1, -1, -1, -1, -1}, 
79   { 1, -1,  0,  3, -1, -1, -1, -1, -1, -1, -1, -1, -1}, 
80   { 2,  0, -1, -1,  3, -1, -1, -1, -1, -1, -1, -1, -1}, 
81   { 3,  1,  2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1} 
82 };
83 #elif defined GC_8
84 int core2test[8][NUM_CORES2TEST] = {
85   { 0, -1, -1,  4,  1, -1, -1, -1, -1, -1,  5,  2, -1}, 
86   { 1, -1,  0,  5,  2, -1, -1, -1,  4, -1,  6,  3, -1}, 
87   { 2, -1,  1,  6,  3, -1, -1,  0,  5, -1,  7, -1, -1}, 
88   { 3, -1,  2,  7, -1, -1, -1,  1,  6, -1, -1, -1, -1}, 
89   { 4,  0, -1, -1,  5, -1, -1, -1, -1, -1, -1,  6,  1}, 
90   { 5,  1,  4, -1,  6, -1,  0, -1, -1, -1, -1,  7,  2},
91   { 6,  2,  5, -1,  7, -1,  1,  4, -1, -1, -1, -1,  3}, 
92   { 7,  3,  6, -1, -1, -1,  2,  5, -1, -1, -1, -1, -1} 
93 };
94 #elif defined GC_16
95 int core2test[16][NUM_CORES2TEST] = {
96   { 0, -1, -1,  4,  1, -1, -1, -1, -1,  8,  5,  2, -1}, 
97   { 1, -1,  0,  5,  2, -1, -1, -1,  4,  9,  6,  3, -1}, 
98   { 2, -1,  1,  6,  3, -1, -1,  0,  5, 10,  7, -1, -1}, 
99   { 3, -1,  2,  7, -1, -1, -1,  1,  6, 11, -1, -1, -1}, 
100   { 4,  0, -1,  8,  5, -1, -1, -1, -1, 12,  9,  6,  1}, 
101   { 5,  1,  4,  9,  6, -1,  0, -1,  8, 13, 10,  7,  2},
102   { 6,  2,  5, 10,  7, -1,  1,  4,  9, 14, 11, -1,  3}, 
103   { 7,  3,  6, 11, -1, -1,  2,  5, 10, 15, -1, -1, -1}, 
104   { 8,  4, -1, 12,  9,  0, -1, -1, -1, -1, 13, 10,  5}, 
105   { 9,  5,  8, 13, 10,  1,  4, -1, 12, -1, 14, 11,  6}, 
106   {10,  6,  9, 14, 11,  2,  5,  8, 13, -1, 15, -1,  7}, 
107   {11,  7, 10, 15, -1,  3,  6,  9, 14, -1, -1, -1, -1},
108   {12,  8, -1, -1, 13,  4, -1, -1, -1, -1, -1, 14,  9}, 
109   {13,  9, 12, -1, 14,  5,  8, -1, -1, -1, -1, 15, 10}, 
110   {14, 10, 13, -1, 15,  6,  9, 12, -1, -1, -1, -1, 11}, 
111   {15, 11, 14, -1, -1,  7, 10, 13, -1, -1, -1, -1, -1} 
112 };
113 #elif defined GC_32
114 int core2test[32][NUM_CORES2TEST] = {
115   { 0, -1, -1,  4,  1, -1, -1, -1, -1,  8,  5,  2, -1}, 
116   { 1, -1,  0,  5,  2, -1, -1, -1,  4,  9,  6,  3, -1}, 
117   { 2, -1,  1,  6,  3, -1, -1,  0,  5, 10,  7, -1, -1}, 
118   { 3, -1,  2,  7, -1, -1, -1,  1,  6, 11, -1, -1, -1}, 
119   { 4,  0, -1,  8,  5, -1, -1, -1, -1, 12,  9,  6,  1}, 
120   { 5,  1,  4,  9,  6, -1,  0, -1,  8, 13, 10,  7,  2},
121   { 6,  2,  5, 10,  7, -1,  1,  4,  9, 14, 11, -1,  3}, 
122   { 7,  3,  6, 11, -1, -1,  2,  5, 10, 15, -1, -1, -1}, 
123   { 8,  4, -1, 12,  9,  0, -1, -1, -1, 16, 13, 10,  5}, 
124   { 9,  5,  8, 13, 10,  1,  4, -1, 12, 17, 14, 11,  6}, 
125   {10,  6,  9, 14, 11,  2,  5,  8, 13, 18, 15, -1,  7}, 
126   {11,  7, 10, 15, -1,  3,  6,  9, 14, 19, -1, -1, -1},
127   {12,  8, -1, 16, 13,  4, -1, -1, -1, 20, 17, 14,  9}, 
128   {13,  9, 12, 17, 14,  5,  8, -1, 16, 21, 18, 15, 10}, 
129   {14, 10, 13, 18, 15,  6,  9, 12, 17, 22, 19, -1, 11}, 
130   {15, 11, 14, 19, -1,  7, 10, 13, 18, 23, -1, -1, -1}, 
131   {16, 12, -1, 20, 17,  8, -1, -1, -1, 24, 21, 18, 13}, 
132   {17, 13, 16, 21, 18,  9, 12, -1, 20, 25, 22, 19, 14},
133   {18, 14, 17, 22, 19, 10, 13, 16, 21, 26, 23, -1, 15}, 
134   {19, 15, 18, 23, -1, 11, 14, 17, 22, 27, -1, -1, -1}, 
135   {20, 16, -1, 24, 21, 12, -1, -1, -1, 28, 25, 22, 17}, 
136   {21, 17, 20, 25, 22, 13, 16, -1, 24, 29, 26, 23, 18}, 
137   {22, 18, 21, 26, 23, 14, 17, 20, 25, 30, 27, -1, 19}, 
138   {23, 19, 22, 27, -1, 15, 18, 21, 26, 31, -1, -1, -1},
139   {24, 20, -1, 28, 25, 16, -1, -1, -1, -1, 29, 26, 21}, 
140   {25, 21, 24, 29, 26, 17, 20, -1, 28, -1, 30, 27, 22}, 
141   {26, 22, 25, 30, 27, 18, 21, 24, 29, -1, 31, -1, 23}, 
142   {27, 23, 26, 31, -1, 19, 22, 25, 30, -1, -1, -1, -1}, 
143   {28, 24, -1, -1, 29, 20, -1, -1, -1, -1, -1, 30, 25}, 
144   {29, 25, 28, -1, 30, 21, 24, -1, -1, -1, -1, 31, 26},
145   {30, 26, 29, -1, 31, 22, 25, 28, -1, -1, -1, -1, 27}, 
146   {31, 27, 30, -1, -1, 23, 26, 29, -1, -1, -1, -1, -1} 
147 };
148 #elif defined GC_36
149 int core2test[36][NUM_CORES2TEST] = {
150   { 0, -1, -1,  6,  1, -1, -1, -1, -1, 12,  7,  2, -1}, 
151   { 1, -1,  0,  7,  2, -1, -1, -1,  6, 13,  8,  3, -1}, 
152   { 2, -1,  1,  8,  3, -1, -1,  0,  7, 14,  9,  4, -1}, 
153   { 3, -1,  2,  9,  4, -1, -1,  1,  8, 15, 10,  5, -1}, 
154   { 4, -1,  3, 10,  5, -1, -1,  2,  9, 16, 11, -1, -1}, 
155   { 5, -1,  4, 11, -1, -1, -1,  3, 10, 17, -1, -1, -1},
156   { 6,  0, -1, 12,  7, -1, -1, -1, -1, 18, 13,  8,  1}, 
157   { 7,  1,  6, 13,  8, -1,  0, -1, 12, 19, 14,  9,  2}, 
158   { 8,  2,  7, 14,  9, -1,  1,  6, 13, 20, 15, 10,  3}, 
159   { 9,  3,  8, 15, 10, -1,  2,  7, 14, 21, 16, 11,  4}, 
160   {10,  4,  9, 16, 11, -1,  3,  8, 15, 22, 17, -1,  5}, 
161   {11,  5, 10, 17, -1, -1,  4,  9, 16, 23, -1, -1, -1},
162   {12,  6, -1, 18, 13,  0, -1, -1, -1, 24, 19, 14,  7}, 
163   {13,  7, 12, 19, 14,  1,  6, -1, 18, 25, 20, 15,  8}, 
164   {14,  8, 13, 20, 15,  2,  7, 12, 19, 26, 21, 16,  9}, 
165   {15,  9, 14, 21, 16,  3,  8, 13, 20, 27, 22, 17, 10}, 
166   {16, 10, 15, 22, 17,  4,  9, 14, 21, 28, 23, -1, 11}, 
167   {17, 11, 16, 23, -1,  5, 10, 15, 22, 29, -1, -1, -1},
168   {18, 12, -1, 24, 19,  6, -1, -1, -1, 30, 25, 20, 13}, 
169   {19, 13, 18, 25, 20,  7, 12, -1, 24, 31, 26, 21, 14}, 
170   {20, 14, 19, 26, 21,  8, 13, 18, 25, 32, 27, 22, 15}, 
171   {21, 15, 20, 27, 22,  9, 14, 19, 26, 33, 28, 23, 16}, 
172   {22, 16, 21, 28, 23, 10, 15, 20, 27, 34, 29, -1, 17}, 
173   {23, 17, 22, 29, -1, 11, 16, 21, 28, 35, -1, -1, -1},
174   {24, 18, -1, 30, 25, 12, -1, -1, -1, -1, 31, 26, 19}, 
175   {25, 19, 24, 31, 26, 13, 18, -1, 30, -1, 32, 27, 20}, 
176   {26, 20, 25, 32, 27, 14, 19, 24, 31, -1, 33, 28, 21}, 
177   {27, 21, 26, 33, 28, 15, 20, 25, 32, -1, 34, 29, 22}, 
178   {28, 22, 27, 34, 29, 16, 21, 26, 33, -1, 35, -1, 23}, 
179   {29, 23, 28, 35, -1, 17, 22, 27, 34, -1, -1, -1, -1},
180   {30, 24, -1, -1, 31, 18, -1, -1, -1, -1, -1, 32, 25}, 
181   {31, 25, 30, -1, 32, 19, 24, -1, -1, -1, -1, 33, 26},
182   {32, 26, 31, -1, 33, 20, 25, 30, -1, -1, -1, 34, 27}, 
183   {33, 27, 32, -1, 34, 21, 26, 31, -1, -1, -1, 35, 28}, 
184   {34, 28, 33, -1, 35, 22, 27, 32, -1, -1, -1, -1, 29}, 
185   {35, 29, 34, -1, -1, 23, 28, 33, -1, -1, -1, -1, -1}
186 };
187 #elif defined GC_48
188 int core2test[48][NUM_CORES2TEST] = {
189   { 0, -1, -1,  6,  1, -1, -1, -1, -1, 12,  7,  2, -1}, 
190   { 1, -1,  0,  7,  2, -1, -1, -1,  6, 13,  8,  3, -1}, 
191   { 2, -1,  1,  8,  3, -1, -1,  0,  7, 14,  9,  4, -1}, 
192   { 3, -1,  2,  9,  4, -1, -1,  1,  8, 15, 10,  5, -1}, 
193   { 4, -1,  3, 10,  5, -1, -1,  2,  9, 16, 11, -1, -1}, 
194   { 5, -1,  4, 11, -1, -1, -1,  3, 10, 17, -1, -1, -1},
195   { 6,  0, -1, 12,  7, -1, -1, -1, -1, 18, 13,  8,  1}, 
196   { 7,  1,  6, 13,  8, -1,  0, -1, 12, 19, 14,  9,  2}, 
197   { 8,  2,  7, 14,  9, -1,  1,  6, 13, 20, 15, 10,  3}, 
198   { 9,  3,  8, 15, 10, -1,  2,  7, 14, 21, 16, 11,  4}, 
199   {10,  4,  9, 16, 11, -1,  3,  8, 15, 22, 17, -1,  5}, 
200   {11,  5, 10, 17, -1, -1,  4,  9, 16, 23, -1, -1, -1},
201   {12,  6, -1, 18, 13,  0, -1, -1, -1, 24, 19, 14,  7}, 
202   {13,  7, 12, 29, 14,  1,  6, -1, 18, 25, 20, 15,  8}, 
203   {14,  8, 13, 20, 15,  2,  7, 12, 19, 26, 21, 16,  9}, 
204   {15,  9, 14, 21, 16,  3,  8, 13, 20, 27, 22, 17, 10}, 
205   {16, 10, 15, 22, 17,  4,  9, 14, 21, 28, 23, -1, 11}, 
206   {17, 11, 16, 23, -1,  5, 10, 15, 22, 29, -1, -1, -1},
207   {18, 12, -1, 24, 19,  6, -1, -1, -1, 30, 25, 20, 13}, 
208   {19, 13, 18, 25, 20,  7, 12, -1, 24, 31, 26, 21, 14}, 
209   {20, 14, 19, 26, 21,  8, 13, 18, 25, 32, 27, 22, 15}, 
210   {21, 15, 20, 27, 22,  9, 14, 19, 26, 33, 28, 23, 16}, 
211   {22, 16, 21, 28, 23, 10, 15, 20, 27, 34, 29, -1, 17}, 
212   {23, 17, 22, 29, -1, 11, 16, 21, 28, 35, -1, -1, -1},
213   {24, 18, -1, 30, 25, 12, -1, -1, -1, 36, 31, 26, 19}, 
214   {25, 19, 24, 31, 26, 13, 18, -1, 30, 37, 32, 27, 20}, 
215   {26, 20, 25, 32, 27, 14, 19, 24, 31, 38, 33, 28, 21}, 
216   {27, 21, 26, 33, 28, 15, 20, 25, 32, 39, 34, 29, 22}, 
217   {28, 22, 27, 34, 29, 16, 21, 26, 33, 40, 35, -1, 23}, 
218   {29, 23, 28, 35, -1, 17, 22, 27, 34, 41, -1, -1, -1},
219   {30, 24, -1, 36, 31, 18, -1, -1, -1, 42, 37, 32, 25}, 
220   {31, 25, 30, 37, 32, 19, 24, -1, 36, 43, 38, 33, 26}, 
221   {32, 26, 31, 38, 33, 20, 25, 30, 37, 44, 39, 34, 27}, 
222   {33, 27, 32, 39, 34, 21, 26, 31, 38, 45, 40, 35, 28}, 
223   {34, 28, 33, 40, 35, 22, 27, 32, 39, 46, 41, -1, 29}, 
224   {35, 29, 34, 41, -1, 23, 28, 33, 40, 47, -1, -1, -1},
225   {36, 30, -1, 42, 37, 24, -1, -1, -1, -1, 43, 38, 31}, 
226   {37, 31, 36, 43, 38, 25, 30, -1, 42, -1, 44, 39, 32}, 
227   {38, 32, 37, 44, 39, 26, 31, 36, 43, -1, 45, 40, 33}, 
228   {39, 33, 38, 45, 40, 27, 32, 37, 44, -1, 46, 41, 34}, 
229   {40, 34, 39, 46, 41, 28, 33, 38, 45, -1, 47, -1, 35}, 
230   {41, 35, 40, 47, -1, 29, 34, 39, 46, -1, -1, -1, -1},
231   {42, 36, -1, -1, 43, 30, -1, -1, -1, -1, -1, 44, 37}, 
232   {43, 37, 42, -1, 44, 31, 36, -1, -1, -1, -1, 45, 38}, 
233   {44, 38, 43, -1, 45, 32, 37, 42, -1, -1, -1, 46, 39}, 
234   {45, 39, 44, -1, 46, 33, 38, 43, -1, -1, -1, 47, 40}, 
235   {46, 40, 45, -1, 47, 34, 39, 44, -1, -1, -1, -1, 41}, 
236   {47, 41, 46, -1, -1, 35, 40, 45, -1, -1, -1, -1, -1},
237 };
238 #elif defined GC_50
239 int core2test[50][NUM_CORES2TEST] = {
240   { 0, -1, -1,  6,  1, -1, -1, -1, -1, 12,  7,  2, -1}, 
241   { 1, -1,  0,  7,  2, -1, -1, -1,  6, 13,  8,  3, -1}, 
242   { 2, -1,  1,  8,  3, -1, -1,  0,  7, 14,  9,  4, -1}, 
243   { 3, -1,  2,  9,  4, -1, -1,  1,  8, 15, 10,  5, -1}, 
244   { 4, -1,  3, 10,  5, -1, -1,  2,  9, 16, 11, -1, -1}, 
245   { 5, -1,  4, 11, -1, -1, -1,  3, 10, 17, -1, -1, -1},
246   { 6,  0, -1, 12,  7, -1, -1, -1, -1, 18, 13,  8,  1}, 
247   { 7,  1,  6, 13,  8, -1,  0, -1, 12, 19, 14,  9,  2}, 
248   { 8,  2,  7, 14,  9, -1,  1,  6, 13, 20, 15, 10,  3}, 
249   { 9,  3,  8, 15, 10, -1,  2,  7, 14, 21, 16, 11,  4}, 
250   {10,  4,  9, 16, 11, -1,  3,  8, 15, 22, 17, -1,  5}, 
251   {11,  5, 10, 17, -1, -1,  4,  9, 16, 23, -1, -1, -1},
252   {12,  6, -1, 18, 13,  0, -1, -1, -1, 24, 19, 14,  7}, 
253   {13,  7, 12, 29, 14,  1,  6, -1, 18, 25, 20, 15,  8}, 
254   {14,  8, 13, 20, 15,  2,  7, 12, 19, 26, 21, 16,  9}, 
255   {15,  9, 14, 21, 16,  3,  8, 13, 20, 27, 22, 17, 10}, 
256   {16, 10, 15, 22, 17,  4,  9, 14, 21, 28, 23, -1, 11}, 
257   {17, 11, 16, 23, -1,  5, 10, 15, 22, 29, -1, -1, -1},
258   {18, 12, -1, 24, 19,  6, -1, -1, -1, 30, 25, 20, 13}, 
259   {19, 13, 18, 25, 20,  7, 12, -1, 24, 31, 26, 21, 14}, 
260   {20, 14, 19, 26, 21,  8, 13, 18, 25, 32, 27, 22, 15}, 
261   {21, 15, 20, 27, 22,  9, 14, 19, 26, 33, 28, 23, 16}, 
262   {22, 16, 21, 28, 23, 10, 15, 20, 27, 34, 29, -1, 17}, 
263   {23, 17, 22, 29, -1, 11, 16, 21, 28, 35, -1, -1, -1},
264   {24, 18, -1, 30, 25, 12, -1, -1, -1, 36, 31, 26, 19}, 
265   {25, 19, 24, 31, 26, 13, 18, -1, 30, 37, 32, 27, 20}, 
266   {26, 20, 25, 32, 27, 14, 19, 24, 31, 38, 33, 28, 21}, 
267   {27, 21, 26, 33, 28, 15, 20, 25, 32, 39, 34, 29, 22}, 
268   {28, 22, 27, 34, 29, 16, 21, 26, 33, 40, 35, -1, 23}, 
269   {29, 23, 28, 35, -1, 17, 22, 27, 34, 41, -1, -1, -1},
270   {30, 24, -1, 36, 31, 18, -1, -1, -1, 43, 37, 32, 25}, 
271   {31, 25, 30, 37, 32, 19, 24, -1, 36, 44, 38, 33, 26}, 
272   {32, 26, 31, 38, 33, 20, 25, 30, 37, 45, 39, 34, 27}, 
273   {33, 27, 32, 39, 34, 21, 26, 31, 38, 46, 40, 35, 28}, 
274   {34, 28, 33, 40, 35, 22, 27, 32, 39, 47, 41, -1, 29}, 
275   {35, 29, 34, 41, -1, 23, 28, 33, 40, 48, 42, -1, -1},
276   {36, 30, -1, 43, 37, 24, -1, -1, -1, -1, 44, 38, 31}, 
277   {37, 31, 36, 44, 38, 25, 30, -1, 43, -1, 45, 39, 32}, 
278   {38, 32, 37, 45, 39, 26, 31, 36, 44, -1, 46, 40, 33}, 
279   {39, 33, 38, 46, 40, 27, 32, 37, 45, -1, 47, 41, 34}, 
280   {40, 34, 39, 47, 41, 28, 33, 38, 46, -1, 48, 42, 35}, 
281   {41, 35, 40, 48, 42, 29, 34, 39, 47, -1, 49, -1, -1},
282   {42, -1, 41, 49, -1, -1, 35, 40, 48, -1, -1, -1, -1}, 
283   {43, 36, -1, -1, 44, 30, -1, -1, -1, -1, -1, 45, 37}, 
284   {44, 37, 43, -1, 45, 31, 36, -1, -1, -1, -1, 46, 38}, 
285   {45, 38, 44, -1, 46, 32, 37, 43, -1, -1, -1, 47, 39}, 
286   {46, 39, 45, -1, 47, 33, 38, 44, -1, -1, -1, 48, 40}, 
287   {47, 40, 46, -1, 48, 34, 39, 45, -1, -1, -1, 49, 41},
288   {48, 41, 47, -1, 49, 35, 40, 46, -1, -1, -1, -1, 42}, 
289   {49, 42, 48, -1, -1, -1, 41, 47, -1, -1, -1, -1, -1} 
290 };
291 #elif defined GC_56
292 int core2test[56][NUM_CORES2TEST] = {
293   { 0, -1, -1,  7,  1, -1, -1, -1, -1, 14,  8,  2, -1}, 
294   { 1, -1,  0,  8,  2, -1, -1, -1,  7, 15,  9,  3, -1}, 
295   { 2, -1,  1,  9,  3, -1, -1,  0,  8, 16, 10,  4, -1}, 
296   { 3, -1,  2, 10,  4, -1, -1,  1,  9, 17, 11,  5, -1}, 
297   { 4, -1,  3, 11,  5, -1, -1,  2, 10, 18, 12,  6, -1}, 
298   { 5, -1,  4, 12,  6, -1, -1,  3, 11, 19, 13, -1, -1},
299   { 6, -1,  5, 13, -1, -1, -1,  4, 12, 20, -1, -1, -1}, 
300   { 7,  0, -1, 14,  8, -1, -1, -1, -1, 21, 15,  9,  1}, 
301   { 8,  1,  7, 15,  9, -1,  0, -1, 14, 22, 16, 10,  2}, 
302   { 9,  2,  8, 16, 10, -1,  1,  7, 15, 23, 17, 11,  3}, 
303   {10,  3,  9, 17, 11, -1,  2,  8, 16, 24, 18, 12,  4}, 
304   {11,  4, 10, 18, 12, -1,  3,  9, 17, 25, 19, 13,  5},
305   {12,  5, 11, 19, 13, -1,  4, 10, 18, 26, 20, -1,  6}, 
306   {13,  6, 12, 20, -1, -1,  5, 11, 19, 27, -1, -1, -1}, 
307   {14,  7, -1, 21, 15,  0, -1, -1, -1, 28, 22, 16,  8}, 
308   {15,  8, 14, 22, 16,  1,  7, -1, 21, 29, 23, 17,  9}, 
309   {16,  9, 15, 23, 17,  2,  8, 14, 22, 30, 24, 18, 10}, 
310   {17, 10, 16, 24, 18,  3,  9, 15, 23, 31, 25, 19, 11},
311   {18, 11, 17, 25, 19,  4, 10, 16, 24, 32, 26, 20, 12}, 
312   {19, 12, 18, 26, 20,  5, 11, 17, 25, 33, 27, -1, 13}, 
313   {20, 13, 19, 27, -1,  6, 12, 18, 26, 34, -1, -1, -1}, 
314   {21, 14, -1, 28, 22,  7, -1, -1, -1, 35, 29, 23, 15}, 
315   {22, 15, 21, 29, 23,  8, 14, -1, 28, 36, 30, 24, 16}, 
316   {23, 16, 22, 30, 24,  9, 15, 21, 29, 37, 31, 25, 17},
317   {24, 17, 23, 31, 25, 10, 16, 22, 40, 38, 32, 26, 18}, 
318   {25, 18, 24, 32, 26, 11, 17, 23, 31, 39, 33, 27, 19}, 
319   {26, 19, 25, 33, 27, 12, 18, 24, 32, 40, 34, -1, 20}, 
320   {27, 20, 26, 34, -1, 13, 19, 25, 33, 41, -1, -1, -1}, 
321   {28, 21, -1, 35, 29, 14, -1, -1, -1, 42, 36, 30, 22}, 
322   {29, 22, 28, 36, 30, 15, 21, -1, 35, 43, 37, 31, 23},
323   {30, 23, 29, 37, 31, 16, 22, 28, 36, 44, 38, 32, 24}, 
324   {31, 24, 30, 38, 32, 17, 23, 29, 37, 45, 39, 33, 25}, 
325   {32, 25, 31, 39, 33, 18, 24, 30, 38, 46, 40, 34, 26}, 
326   {33, 26, 32, 40, 34, 19, 25, 31, 39, 47, 41, -1, 27}, 
327   {34, 27, 33, 41, -1, 20, 26, 32, 40, 48, -1, -1, -1}, 
328   {35, 28, -1, 42, 36, 21, -1, -1, -1, 49, 43, 37, 29},
329   {36, 29, 35, 43, 37, 22, 28, -1, 42, 50, 44, 38, 30}, 
330   {37, 30, 36, 44, 38, 23, 29, 35, 43, 51, 45, 39, 31}, 
331   {38, 31, 37, 45, 39, 24, 30, 36, 44, 52, 46, 40, 32}, 
332   {39, 32, 38, 46, 40, 25, 31, 37, 45, 53, 47, 41, 33}, 
333   {40, 33, 39, 47, 41, 26, 32, 38, 46, 54, 48, -1, 34}, 
334   {41, 34, 40, 48, -1, 27, 33, 39, 47, 55, -1, -1, -1},
335   {42, 35, -1, 49, 43, 28, -1, -1, -1, -1, 50, 44, 36}, 
336   {43, 36, 42, 50, 44, 29, 35, -1, 49, -1, 51, 45, 37}, 
337   {44, 37, 43, 51, 45, 30, 36, 42, 50, -1, 52, 46, 38}, 
338   {45, 38, 44, 52, 46, 31, 37, 43, 51, -1, 53, 47, 39}, 
339   {46, 39, 45, 53, 47, 32, 38, 44, 52, -1, 54, 48, 40}, 
340   {47, 40, 46, 54, 48, 33, 39, 45, 53, -1, 55, -1, 41},
341   {48, 41, 47, 55, -1, 34, 40, 46, 54, -1, -1, -1, -1}, 
342   {49, 42, -1, -1, 50, 35, -1, -1, -1, -1, -1, 51, 43}, 
343   {50, 43, 49, -1, 51, 36, 42, -1, -1, -1, -1, 52, 44}, 
344   {51, 44, 50, -1, 52, 37, 43, 49, -1, -1, -1, 53, 45}, 
345   {52, 45, 51, -1, 53, 38, 44, 50, -1, -1, -1, 54, 46}, 
346   {53, 46, 52, -1, 54, 39, 45, 51, -1, -1, -1, 55, 47},
347   {54, 47, 53, -1, 55, 40, 46, 52, -1, -1, -1, -1, 48}, 
348   {55, 48, 54, -1, -1, 41, 47, 53, -1, -1, -1, -1, -1}
349 };
350 #elif defined GC_62
351 int core2test[62][NUM_CORES2TEST] = {
352   { 0, -1, -1,  6,  1, -1, -1, -1, -1, 14,  7,  2, -1}, 
353   { 1, -1,  0,  7,  2, -1, -1, -1,  6, 15,  8,  3, -1}, 
354   { 2, -1,  1,  8,  3, -1, -1,  0,  7, 16,  9,  4, -1}, 
355   { 3, -1,  2,  9,  4, -1, -1,  1,  8, 17, 10,  5, -1}, 
356   { 4, -1,  3, 10,  5, -1, -1,  2,  9, 18,  11, -1, -1}, 
357   { 5, -1,  4, 11, -1, -1, -1,  3, 10, 19, 12, -1, -1},
358   { 6,  0, -1, 14,  7, -1, -1, -1, -1, 22, 15,  8,  1}, 
359   { 7,  1,  6, 15,  8, -1,  0, -1, 14, 23, 16,  9,  2}, 
360   { 8,  2,  7, 16,  9, -1,  1,  6, 15, 24, 17, 10,  3}, 
361   { 9,  3,  8, 17, 10, -1,  2,  7, 16, 25, 18, 11,  4}, 
362   {10,  4,  9, 18, 11, -1,  3,  8, 17, 26, 19, 12,  5}, 
363   {11,  5, 10, 19, 12, -1,  4,  9, 18, 27, 20, 13, -1},
364   {12, -1, 11, 20, 13, -1,  5, 10, 19, 28, 21, -1, -1}, 
365   {13, -1,  12, 21, -1, -1, -1, 11, 20, 29, -1, -1, -1}, 
366   {14,  6, -1, 22, 15,  0, -1, -1, -1, 30, 23, 16,  7}, 
367   {15,  7, 14, 23, 16,  1,  6, -1, 22, 31, 24, 17,  8}, 
368   {16,  8, 15, 24, 17,  2,  7, 14, 23, 32, 25, 18,  9}, 
369   {17,  9, 16, 25, 18,  3,  8, 15, 24, 33, 26, 19, 10},
370   {18, 10, 17, 26, 19,  4,   9, 16, 25, 34, 27, 20, 11}, 
371   {19, 11, 18, 27, 20,  5, 10, 17, 26, 35, 28, 21, 12}, 
372   {20, 12, 19, 28, 21, -1, 11, 18, 27, 36, 29, -1, 13}, 
373   {21, 13, 28, 29, -1, -1, 12, 19, 28, 37, -1, -1, -1}, 
374   {22, 14, -1, 30, 23,  6, -1, -1, -1, 38, 31, 24, 15}, 
375   {23, 15, 22, 31, 24,  7, 14, -1, 30, 39, 32, 25, 16},
376   {24, 16, 23, 32, 25,  8, 15, 22, 31, 40, 33, 26, 17}, 
377   {25, 17, 24, 33, 26,  9, 16, 23, 32, 41, 34, 27, 18}, 
378   {26, 18, 25, 34, 27, 10, 17, 24, 33, 42, 35, 28, 19}, 
379   {27, 19, 26, 35, 28, 11, 18, 25, 34, 43, 36, 29, 20}, 
380   {28, 20, 27, 36, 29, 12, 19, 26, 35, 44, 37, -1, 21}, 
381   {29, 21, 28, 37, -1, 13, 20, 27, 36, 45, -1, -1, -1},
382   {30, 22, -1, 38, 31, 14, -1, -1, -1, 46, 39, 32, 23}, 
383   {31, 23, 30, 39, 32, 15, 22, -1, 38, 47, 40, 33, 24}, 
384   {32, 24, 31, 40, 33, 16, 23, 30, 39, 48, 41, 34, 25}, 
385   {33, 25, 32, 41, 34, 17, 24, 31, 40, 49, 42, 35, 26}, 
386   {34, 26, 33, 42, 35, 18, 25, 32, 41, 50, 43, 36, 27}, 
387   {35, 27, 34, 43, 36, 19, 26, 33, 42, 51, 44, 37, 28},
388   {36, 28, 35, 44, 37, 20, 27, 34, 43, 52, 45, -1, 29}, 
389   {37, 29, 36, 45, -1, 21, 28, 35, 44, 53, -1, -1, -1}, 
390   {38, 30, -1, 46, 39, 22, -1, -1, -1, 54, 47, 40, 31}, 
391   {39, 31, 38, 47, 40, 23, 30, -1, 46, 55, 48, 41, 32}, 
392   {40, 32, 39, 48, 41, 24, 31, 38, 47, 56, 49, 42, 33}, 
393   {41, 33, 40, 49, 42, 25, 32, 39, 48, 57, 50, 43, 34},
394   {42, 34, 41, 50, 43, 26, 33, 40, 49, 58, 51, 44, 35}, 
395   {43, 35, 42, 51, 44, 27, 34, 41, 50, 59, 52, 45, 36}, 
396   {44, 36, 43, 52, 45, 28, 35, 42, 51, 60, 53, -1, 37}, 
397   {45, 37, 44, 53, -1, 29, 36, 43, 52, 61, -1, -1}, 
398   {46, 38, -1, 54, 47, 30, -1, -1, -1, -1, 55, 48, 39}, 
399   {47, 39, 46, 55, 48, 31, 38, -1, 54, -1, 56, 49, 40},
400   {48, 40, 47, 56, 49, 32, 39, 46, 55 -1, 57, 50, 41}, 
401   {49, 41, 48, 57, 50, 33, 40, 47, 56, -1, 58, 51, 42}, 
402   {50, 42, 49, 58, 51, 34, 41, 48, 57, -1, 59, 52, 43}, 
403   {51, 43, 50, 59, 52, 35, 42, 49, 58, -1, 60, 53, 44}, 
404   {52, 44, 51, 60, 53, 36, 43, 50, 59, -1, 61, -1, 45}, 
405   {53, 45, 52, 61, -1, 37, 44, 51, 60, -1, -1, -1, -1},
406   {54, 46, -1, -1, 55, 38, -1, -1, -1, -1, -1, 56, 47}, 
407   {55, 47, 54, -1, 56, 39, 46, -1, -1, -1, -1, 57, 48}, 
408   {56, 48, 55, -1, 57, 40, 47, 54, -1, -1, -1, 58, 49}, 
409   {57, 49, 56, -1, 58, 41, 48, 55, -1, -1, -1, 59, 50}, 
410   {58, 50, 57, -1, 59, 42, 49, 56, -1, -1, -1, 60, 51}, 
411   {59, 51, 58, -1, 60, 43, 50, 57, -1, -1, -1, 61, 52},
412   {60, 52, 59, -1, 61, 44, 51, 58, -1, -1, -1, -1, 53}, 
413   {61, 53, 60, -1, -1, 45, 52, 59, -1, -1, -1, -1, -1}
414 };
415 #endif // GC_1
416 #endif // SMEMF
417
418 INLINE void setupsmemmode(void) {
419 #ifdef SMEML
420   // Only allocate local mem chunks to each core.
421   // If a core has used up its local shared memory, start gc.
422   bamboo_smem_mode = SMEMLOCAL;
423 #elif defined SMEMF
424   // Allocate the local shared memory to each core with the highest priority,
425   // if a core has used up its local shared memory, try to allocate the 
426   // shared memory that belong to its neighbours, if also failed, start gc.
427   bamboo_smem_mode = SMEMFIXED;
428 #elif defined SMEMM
429   // Allocate the local shared memory to each core with the highest priority,
430   // if a core has used up its local shared memory, try to allocate the 
431   // shared memory that belong to its neighbours first, if failed, check 
432   // current memory allocation rate, if it has already reached the threshold,
433   // start gc, otherwise, allocate the shared memory globally.  If all the 
434   // shared memory has been used up, start gc.
435   bamboo_smem_mode = SMEMMIXED;
436 #elif defined SMEMG
437   // Allocate all the memory chunks globally, do not consider the host cores
438   // When all the shared memory are used up, start gc.
439   bamboo_smem_mode = SMEMGLOBAL;
440 #else
441   // defaultly using local mode
442   bamboo_smem_mode = SMEMLOCAL;
443 #endif 
444
445
446 INLINE void * mallocmem(int tofindb,
447                         int totest,
448                         int size,
449                         int * allocsize) {
450   void * mem = NULL;
451   // find suitable block
452   mem=gcbaseva+bamboo_smemtbl[tofindb]+((tofindb<NUMCORES4GC)?
453       (BAMBOO_SMEM_SIZE_L*tofindb):
454       (BAMBOO_LARGE_SMEM_BOUND+(tofindb-NUMCORES4GC)*BAMBOO_SMEM_SIZE));
455   *allocsize = size;
456   // set bamboo_smemtbl
457   for(int i = tofindb; i <= totest; i++) {
458     bamboo_smemtbl[i]=(i<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
459   }
460   if(tofindb == bamboo_free_block) {
461     bamboo_free_block = totest+1;
462   }
463   return mem;
464 }
465
466 INLINE void * searchBlock4Mem(int* tofindb, 
467                               int* totest,
468                               int gccorenum,
469                               int isize,
470                               int * allocsize) {
471   int i=0;
472   int j=0;
473   int size = 0;
474   int bound = BAMBOO_SMEM_SIZE_L;
475   while(*totest<(gcnumblock-bamboo_reserved_smem)) {
476     bound = (*totest<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
477     int nsize = bamboo_smemtbl[*totest];
478     if((nsize==bound)||((nsize != 0)&&(*totest != *tofindb))) {
479       // a fully/partially occupied partition, can not be appended 
480       //the last continuous block is not big enough,check the next local block
481       i++;
482       if(2==i) {
483         i = 0;
484         j++;
485       }
486       *tofindb=*totest=gc_core2block[2*gccorenum+i]+(NUMCORES4GC*2)*j;
487     } else {
488       // an empty block or a partially occupied block that can be set as the 
489       // first block
490       if(*totest == *tofindb) {
491         // the first partition
492         size = bound - nsize;
493       } else if(nsize == 0) {
494         // an empty partition, can be appended
495         size += bound;
496       } 
497       if(size >= isize) {
498         // have enough space in the block, malloc
499         return mallocmem(*tofindb, *totest, size, allocsize);
500         break;
501       } else {
502         // no enough space yet, try to append next continuous block
503         *totest = *totest + 1;
504       }  
505     }
506   }
507   return NULL;
508 }
509
510 INLINE void * searchBlock4Mem_global(int* tofindb, 
511                                      int* totest,
512                                      int isize,
513                                      int * allocsize) {
514   int i=0;
515   int j=0;
516   int size = 0;
517   int bound = BAMBOO_SMEM_SIZE_L;
518   while(*totest<(gcnumblock-bamboo_reserved_smem)) {
519     bound = (*totest<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
520     int nsize = bamboo_smemtbl[*totest];
521     if((nsize==bound)||((nsize != 0)&&(*totest != *tofindb))) {
522       // a fully/partially occupied partition, can not be appended 
523       // set the next block as a new start
524       *totest = *totest+1;
525       *tofindb = *totest;
526     } else {
527       // an empty block or a partially occupied block that can be set as the 
528       // first block
529       if(*totest == *tofindb) {
530         // the first partition
531         size = bound - nsize;
532       } else if(nsize == 0) {
533         // an empty partition, can be appended
534         size += bound;
535       } 
536       if(size >= isize) {
537         // have enough space in the block, malloc
538         return mallocmem(*tofindb, *totest, size, allocsize);
539         break;
540       } else {
541         // no enough space yet, try to append next continuous block
542         *totest = *totest + 1;
543       }  
544     }
545   }
546   return NULL;
547 }
548
549 // Only allocate local mem chunks to each core.
550 // If a core has used up its local shared memory, start gc.
551 void * localmalloc_I(int coren,
552                      int isize,
553                      int * allocsize) {
554   void * mem = NULL;
555   int gccorenum = (coren<NUMCORES4GC)?(coren):(coren%NUMCORES4GC);
556   int tofindb = gc_core2block[2*gccorenum];
557   int totest = tofindb;
558   mem = searchBlock4Mem(&tofindb, &totest, gccorenum, isize, allocsize);
559   if(mem == NULL) {
560     // no more local mem, do not find suitable block
561     *allocsize = 0;
562   }
563   return mem;
564
565
566 #ifdef SMEMF
567 // Allocate the local shared memory to each core with the highest priority,
568 // if a core has used up its local shared memory, try to allocate the 
569 // shared memory that belong to its neighbours, if also failed, start gc.
570 void * fixedmalloc_I(int coren,
571                      int isize,
572                      int * allocsize) {
573   void * mem;
574   int k;
575   int gccorenum = (coren<NUMCORES4GC)?(coren):(coren%NUMCORES4GC);
576   int totest, tofindb;
577   int bound = BAMBOO_SMEM_SIZE_L;
578   int foundsmem = 0;
579   int size = 0;
580   for(k=0; k<NUM_CORES2TEST; k++) {
581     if(core2test[gccorenum][k] == -1) {
582       // try next neighbour
583       continue;
584     }
585     tofindb=totest=gc_core2block[2*core2test[gccorenum][k]];
586     mem=searchBlock4Mem(&tofindb,&totest,core2test[gccorenum][k],
587         isize,allocsize);
588     if(mem != NULL) {
589       return mem;
590     }
591   }
592   // no more memory available on either coren or its neighbour cores
593   *allocsize = 0;
594   return NULL;
595
596 #endif 
597
598 #ifdef SMEMM
599 // Allocate the local shared memory to each core with the highest priority,
600 // if a core has used up its local shared memory, try to allocate the 
601 // shared memory that belong to its neighbours first, if failed, check 
602 // current memory allocation rate, if it has already reached the threshold,
603 // start gc, otherwise, allocate the shared memory globally.  If all the 
604 // shared memory has been used up, start gc.
605 void * mixedmalloc_I(int coren,
606                      int isize,
607                      int * allocsize) {
608   void * mem;
609   int k;
610   int gccorenum = (coren < NUMCORES4GC) ? (coren) : (coren % NUMCORES4GC);
611   int totest,tofindb;
612   int bound = BAMBOO_SMEM_SIZE_L;
613   int foundsmem = 0;
614   int size = 0;
615   for(k=0; k<NUM_CORES2TEST; k++) {
616     if(core2test[gccorenum][k] == -1) {
617       // try next neighbour
618       continue;
619     }
620     tofindb=totest=gc_core2block[2*core2test[gccorenum][k]];
621     mem=searchBlock4Mem(&tofindb,&totest,core2test[gccorenum][k],
622         isize,allocsize);
623     if(mem != NULL) {
624       gcmem_mixed_usedmem += size;
625       return mem;
626     }
627   }
628   if(gcmem_mixed_usedmem >= gcmem_mixed_threshold) {
629     // no more memory available on either coren or its neighbour cores
630     *allocsize = 0;
631     return NULL; 
632   } else {
633     // try allocate globally
634     mem = globalmalloc_I(coren, isize, allocsize);
635     if(mem != NULL) {
636       gcmem_mixed_usedmem += size;
637     }
638     return mem;
639   }
640
641 #endif 
642
643 // Allocate all the memory chunks globally, do not consider the host cores
644 // When all the shared memory are used up, start gc.
645 void * globalmalloc_I(int coren,
646                       int isize,
647                       int * allocsize) {
648   void * mem = NULL;
649   int tofindb = bamboo_free_block;
650   int totest = tofindb;
651   int bound = BAMBOO_SMEM_SIZE_L;
652   int foundsmem = 0;
653   int size = 0;
654   if(tofindb > gcnumblock-1-bamboo_reserved_smem) {
655     // Out of shared memory
656     *allocsize = 0;
657     return NULL;
658   }
659   mem=searchBlock4Mem_global(&tofindb, &totest, isize, allocsize);
660   if(mem == NULL) {
661     *allocsize = 0;
662   }
663   return mem;
664
665
666 // malloc from the shared memory
667 void * smemalloc_I(int coren,
668                    int size,
669                    int * allocsize) {
670   void * mem = NULL;
671   int isize = size+(BAMBOO_CACHE_LINE_SIZE);
672
673   // go through the bamboo_smemtbl for suitable partitions
674   switch(bamboo_smem_mode) {
675   case SMEMLOCAL: {
676     mem = localmalloc_I(coren, isize, allocsize);
677     break;
678   }
679
680   case SMEMFIXED: {
681 #ifdef SMEMF
682         mem = fixedmalloc_I(coren, isize, allocsize);
683 #else
684         // not supported yet
685         BAMBOO_EXIT(0xe101);
686 #endif
687     break;
688   }
689
690   case SMEMMIXED: {
691 #ifdef SMEMM
692         mem = mixedmalloc_I(coren, isize, allocsize);
693 #else
694         // not supported yet
695     BAMBOO_EXIT(0xe102);
696 #endif
697     break;
698   }
699
700   case SMEMGLOBAL: {
701     mem = globalmalloc_I(coren, isize, allocsize);
702     break;
703   }
704
705   default:
706     break;
707   }
708
709   if(mem == NULL) {
710     // no enough shared global memory
711     *allocsize = 0;
712         if(!gcflag) {
713           gcflag = true;
714           if(!gcprocessing) {
715       // inform other cores to stop and wait for gc
716       gcprecheck = true;
717       for(int i = 0; i < NUMCORESACTIVE; i++) {
718         // reuse the gcnumsendobjs & gcnumreceiveobjs
719         gcnumsendobjs[0][i] = 0;
720         gcnumreceiveobjs[0][i] = 0;
721       }
722       GC_SEND_MSG_1_TO_CLIENT(GCSTARTPRE);
723           }
724         }
725         return NULL;
726   }
727   return mem;
728 }
729 #else
730 // malloc from the shared memory
731 void * smemalloc_I(int coren,
732                    int size,
733                    int * allocsize) {
734   void * mem = NULL;
735   int toallocate = (size>(BAMBOO_SMEM_SIZE)) ? (size) : (BAMBOO_SMEM_SIZE);
736   if(toallocate > bamboo_free_smem_size) {
737     // no enough mem
738     mem = NULL;
739   } else {
740     mem = (void *)bamboo_free_smemp;
741     bamboo_free_smemp = ((void*)bamboo_free_smemp) + toallocate;
742     bamboo_free_smem_size -= toallocate;
743   }
744   *allocsize = toallocate;
745   if(mem == NULL) {
746     // no enough shared global memory
747     *allocsize = 0;
748     BAMBOO_EXIT(0xe103);
749   }
750   return mem;
751
752 #endif // MULTICORE_GC
753
754 #endif // MULTICORE