[mpich-discuss] haar wavelet x'formation

Anuj Patel indyaah at gmail.com
Wed Nov 25 03:32:10 CST 2009


this is a sequential application for image compression. so please help me to
convert this in to the parallel application to run on mpich-2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20091125/05651cc1/attachment.htm>
-------------- next part --------------
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <stdlib.h>

#define N 512

/* timer structure */
typedef struct {
  struct timeval s;
  struct timeval e;
} TIMER, *TIMERPTR;


/* 
   Start the timer 
*/
void startTimer(TIMERPTR tp)
{
  gettimeofday(&tp->s,NULL);
}

/* 
   Return the time since the timer was started in microseconds
*/
unsigned long getTime(TIMERPTR tp)
{
  gettimeofday(&tp->e,NULL);
  return ((tp->e.tv_sec*((unsigned long)1000000)+tp->e.tv_usec) - 
	  (tp->s.tv_sec*((unsigned long)1000000)+tp->s.tv_usec));
}









int main()
{

int img[N][N],t1[N][N],t2[N][N],res[N][N];
int i,j,k;
TIMERPTR myTimer;
	unsigned long runtime;
		
 

   myTimer=(TIMERPTR)malloc(sizeof(TIMER));
   startTimer(myTimer);


for (i=0;i<N;i++)
for (j=0;j<N;j++)
  {
	img[i][j] = rand()%16;
	if(img[i][j] < 10)
	img[i][j]+=8;
  }

for(i=0,k=0;k<N;i+=2,k++)
  for(j=0;j<N;j++)
  {
	if(i<N)
 	{
		t1[k][j] = (img[i][j]+img[i+1][j])*0.5;
	}
	
	else
	{
		t1[k][j] = (img[i%N][j]-img[(i+1)%N][j])*0.5;
	}		
  }


for(i=0;i<N;i++)
for(j=0,k=0;j<N*2;j+=2,k++)
  {
	if(j<N)
 	{
		t2[i][k] = (t1[i][j]+t1[i][j+1])*0.5;
	}
	
	else
	{
		t2[i][k] = (t1[i][j%N]-t1[i][(j+1)%N])*0.5;
	}		
  }
for (i=0;i<N;i++)
{
for (j=0;j<N;j++)
  {
	printf("%d\t",t2[i][j]);
  }
printf("\n");
}

runtime=getTime(myTimer);
printf("Run time was %ld.\n",runtime);


return 0;
}


More information about the mpich-discuss mailing list