00001 #include <stdio.h> 00002 #include <stdlib.h> 00003 #include <string.h> 00004 #include "timer.h" 00005 #include "ndim.h" 00006 #include "xassert.h" 00007 00008 00009 #define N1 3 00010 #define N2 2 00011 #define N3 5 00012 #define N4 3 00013 00014 int x[N1][N2][N3][N4]; 00015 int dims[4]={N1,N2,N3,N4}; 00016 int start[4]={0,0,0,0}, end[4]={N1-1,N2-1,N3-1,N4-1}; 00017 int start1[4]={0,0,0,0}, end1[4]={N1-1,N2-1,N3-1,N4-1}; 00018 00019 void print(int x[N1][N2][N3][N4]) 00020 { 00021 int i0,i1,i2,i3; 00022 00023 for (i3=0; i3<N1; i3++) 00024 { 00025 for (i2=0; i2<N2; i2++) 00026 { 00027 printf("x[%d][%d][*][*] = \n",i3,i2); 00028 for (i1=0; i1<N3; i1++) 00029 { 00030 for (i0=0; i0<N4; i0++) 00031 printf("%04d ",x[i3][i2][i1][i0]); 00032 printf("\n"); 00033 } 00034 printf("\n"); 00035 } 00036 printf("\n"); 00037 } 00038 printf("\n"); 00039 } 00040 00041 int main() 00042 { 00043 int N; 00044 int i,i0,i1,i2,i3, total, val; 00045 int *y; 00046 int perm[4] = {1,0,2,3}; 00047 00048 N = N1*N2*N3*N4; 00049 StartTimer(1); 00050 for (i3=0; i3<N1; i3++) 00051 for (i2=0; i2<N2; i2++) 00052 for (i1=0; i1<N3; i1++) 00053 for (i0=0; i0<N4; i0++) 00054 x[i3][i2][i1][i0] = i0 + 10*i1 + 100*i2 + 1000*i3; 00055 printf("time spent generating data = %f\n",StopTimer(1)); 00056 y = malloc(N*sizeof(int)); 00057 XASSERT(y); 00058 memset(y, 0, N*sizeof(int)); 00059 StartTimer(1); 00060 ndim_unpack(sizeof(int), 4, dims, start, end, 00061 (unsigned char *) x, (unsigned char *) y); 00062 printf("time spent unpacking data = %f\n",StopTimer(1)); 00063 00064 printf("y = \n"); 00065 if (N<1000) 00066 { 00067 total = end[0]-start[0]+1; 00068 for(i=1; i<4; i++) 00069 total *= (end[i]-start[i]+1); 00070 for(i=0; i<total; i++) 00071 printf("%04d\n",y[i]); 00072 } 00073 00074 00075 StartTimer(1); 00076 memset(x, 0, N*sizeof(int)); 00077 ndim_pack(sizeof(int), 4, dims, start1, end1, 00078 (unsigned char *) y, (unsigned char *) x); 00079 printf("time spent packing data = %f\n",StopTimer(1)); 00080 00081 if (N<1000) 00082 print(x); 00083 00084 00085 memset(y, 0, N*sizeof(int)); 00086 ndim_permute(sizeof(int), 4, dims, perm, 00087 (unsigned char *) x, (unsigned char *) y); 00088 00089 if (N<1000) 00090 print(y); 00091 return 0; 00092 }