P
Pasacco
dear
I want to ask help on this problem.
Array a[N] is partitioned into a0[N/2] and a1[N/2] in main(). Then
a1[N/2] is partitioned into a2[N/4] and a3[N/4] in th_partition()
function. And I think this problem is something about parameter
passing.
If someone give me comment, it will be thankful.
thankyou very much
/***********************************************/
#include <stdio.h>
void* th_partition(void*);
#define N 20 // number of elements
struct tag{
int *a0_temp; // temporary array
int *a1_temp;
int *a2_temp;
int *a3_temp;
int *a0_N; // number of elements for each array
int *a1_N;
int *a2_N;
int *a3_N;
}arrays;
int main(int argc, char* argv[])
{
int i,j,*pt;
int a[N];
// Initial array (N elements)
for(i=0;i<N;i++)
a = i;
pt = a;
/* partition of a[] ==> a0[] and a1[] */
/* j : position in the middle */
j = N / 2;
int tmp0[j];
int tmp1[N-j];
arrays.a0_N = (void*) (j);
arrays.a1_N = (void*) (N-j);
for(i=0;i<j;i++)
tmp0=a;
for(i=j;i<N;i++)
tmp1[i-j]=a;
arrays.a0_temp = tmp0;
arrays.a1_temp = tmp1;
for(i=0;i<j;i++)
printf(" %d ",arrays.a0_temp);
printf("\n");
for(i=0;i<N-j;i++)
printf(" %d ",arrays.a1_temp);
printf("\n");
th_partition(&arrays);
// Test ===> strange !!
int test = (int)arrays.a2_N;
for(i=0;i<test;i++)
printf(" %d ", arrays.a2_temp);
printf("\n");
}
/* Partition of a1[] ==> a2[] and a3[] */
void* th_partition(void* parameters)
{
int i,j,M;
struct tag* para = (struct tag*)parameters;
M = (int) para->a1_N;
j = M / 2;
int tmp2[j];
int tmp3[M-j];
para->a2_N = (void* )(j );
para->a3_N = (void* )(M-j);
for(i=0;i<j;i++)
tmp2=para->a1_temp;
for(i=j;i<M;i++)
tmp3[i-j]=para->a1_temp;
para->a2_temp = tmp2;
for(i=0;i<j;i++)
printf(" %d ",para->a2_temp);
printf("\n");
para->a3_temp = tmp3;
for(i=0;i<M-j;i++)
printf(" %d ",para->a3_temp);
printf(" \n ");
}
I want to ask help on this problem.
Array a[N] is partitioned into a0[N/2] and a1[N/2] in main(). Then
a1[N/2] is partitioned into a2[N/4] and a3[N/4] in th_partition()
function. And I think this problem is something about parameter
passing.
If someone give me comment, it will be thankful.
thankyou very much
/***********************************************/
#include <stdio.h>
void* th_partition(void*);
#define N 20 // number of elements
struct tag{
int *a0_temp; // temporary array
int *a1_temp;
int *a2_temp;
int *a3_temp;
int *a0_N; // number of elements for each array
int *a1_N;
int *a2_N;
int *a3_N;
}arrays;
int main(int argc, char* argv[])
{
int i,j,*pt;
int a[N];
// Initial array (N elements)
for(i=0;i<N;i++)
a = i;
pt = a;
/* partition of a[] ==> a0[] and a1[] */
/* j : position in the middle */
j = N / 2;
int tmp0[j];
int tmp1[N-j];
arrays.a0_N = (void*) (j);
arrays.a1_N = (void*) (N-j);
for(i=0;i<j;i++)
tmp0=a;
for(i=j;i<N;i++)
tmp1[i-j]=a;
arrays.a0_temp = tmp0;
arrays.a1_temp = tmp1;
for(i=0;i<j;i++)
printf(" %d ",arrays.a0_temp);
printf("\n");
for(i=0;i<N-j;i++)
printf(" %d ",arrays.a1_temp);
printf("\n");
th_partition(&arrays);
// Test ===> strange !!
int test = (int)arrays.a2_N;
for(i=0;i<test;i++)
printf(" %d ", arrays.a2_temp);
printf("\n");
}
/* Partition of a1[] ==> a2[] and a3[] */
void* th_partition(void* parameters)
{
int i,j,M;
struct tag* para = (struct tag*)parameters;
M = (int) para->a1_N;
j = M / 2;
int tmp2[j];
int tmp3[M-j];
para->a2_N = (void* )(j );
para->a3_N = (void* )(M-j);
for(i=0;i<j;i++)
tmp2=para->a1_temp;
for(i=j;i<M;i++)
tmp3[i-j]=para->a1_temp;
para->a2_temp = tmp2;
for(i=0;i<j;i++)
printf(" %d ",para->a2_temp);
printf("\n");
para->a3_temp = tmp3;
for(i=0;i<M-j;i++)
printf(" %d ",para->a3_temp);
printf(" \n ");
}