1 /* { dg-do run } */
2 /* { dg-options "-fwhole-program" } */
3
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <math.h>
8 #include <string.h>
9
10 void mem_init (void);
11 int ARCHnodes, ARCHnodes1;
12 int ***vel;
13
14 /* The two inner dimesions of matrix escape because of the
15 assignment vel[1]= ...
16 VEL is not Flattened. */
17
18 /*--------------------------------------------------------------------------*/
19
20 int
main(int argc,char ** argv)21 main (int argc, char **argv)
22 {
23 int i, j, k;
24
25 ARCHnodes = 2;
26 ARCHnodes1 = 4;
27
28 /* Dynamic memory allocations and initializations */
29
30 mem_init ();
31
32 for (i = 0; i < ARCHnodes; i++)
33 {
34 for (j = 0; j < 3; j++)
35 {
36 for (k = 0; k < ARCHnodes1; k++)
37 printf ("[%d][%d][%d]=%d ", i, j, k, vel[i][j][k]);
38 printf ("\n");
39 }
40 printf ("\n");
41 }
42 for (i = 0; i < ARCHnodes-1; i++)
43 for (j = 0; j < 3; j++)
44 free (vel[i][j]);
45
46 for (i = 0; i < ARCHnodes-1; i++)
47 free (vel[i]);
48
49 free (vel);
50 return 0;
51 }
52
53 /*--------------------------------------------------------------------------*/
54 /* Dynamic memory allocations and initializations */
55
56 void
mem_init(void)57 mem_init (void)
58 {
59
60 int i, j, k,d;
61
62 d = 0;
63 vel = (int ***) malloc (ARCHnodes * sizeof (int **));
64
65 for (i = 0; i < ARCHnodes; i++)
66 {
67 vel[i] = (int **) malloc (3 * sizeof (int *));
68 if (vel[i] == (int **) NULL)
69 {
70 printf ("malloc failed for vel[%d]\n", i);
71 exit (0);
72 }
73 }
74 for (i = 0; i < ARCHnodes; i++)
75 {
76 for (j = 0; j < 3; j++)
77 {
78 vel[i][j] = (int *) malloc (ARCHnodes1 * sizeof (int));
79 }
80 }
81 for (i = 0; i < ARCHnodes; i++)
82 {
83 for (j = 0; j < 3; j++)
84 {
85 for (k = 0; k < ARCHnodes1; k++)
86 {
87 vel[i][j][k] = d;
88 d++;
89 }
90 }
91 }
92 vel[1] = vel[0];
93 }
94
95 /*--------------------------------------------------------------------------*/
96