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