PIPS
jacobi.c File Reference
#include <stdio.h>
#include <stdlib.h>
+ Include dependency graph for jacobi.c:

Go to the source code of this file.

Macros

#define SIZE   832
 
#define T   64
 

Typedefs

typedef float float_t
 

Functions

void get_data (char filename[])
 
void write_data (char filename[])
 
void jacobi ()
 
int main (int argc, char *argv[])
 

Variables

float_t space [SIZE][SIZE]
 
float_t save [SIZE][SIZE]
 

Macro Definition Documentation

◆ SIZE

#define SIZE   832

Definition at line 4 of file jacobi.c.

◆ T

#define T   64

Definition at line 5 of file jacobi.c.

Typedef Documentation

◆ float_t

typedef float float_t

Definition at line 3 of file jacobi.c.

Function Documentation

◆ get_data()

void get_data ( char  filename[])

Get *.pgm file type

Skip comment lines

Put back good char

Get image dimensions

Get grey levels

Get ONE carriage return

Definition at line 11 of file jacobi.c.

11  {
12  int i, j, nx, ny;
13  unsigned char c;
14  FILE *fp;
15 
16  if ((fp = fopen(filename, "r")) == NULL) {
17  perror("Error loading file");
18  exit(1);
19  }
20 
21  /* Get *.pgm file type */
22  c = fgetc(fp);
23  c = fgetc(fp);
24 
25  /* Skip comment lines */
26  do {
27  while((c = fgetc(fp)) != '\n');
28  } while((c = fgetc(fp)) == '#');
29 
30  /* Put back good char */
31  ungetc(c,fp);
32 
33  /* Get image dimensions */
34  fscanf(fp, "%d %d\n", &nx, &ny);
35  /* Get grey levels */
36  fscanf(fp,"%d",&i);
37  /* Get ONE carriage return */
38  fgetc(fp);
39  printf("Input image : x=%d y=%d grey=%d\n", nx, ny, i);
40 
41 
42  for(i = 0;i < SIZE; i++)
43  for(j = 0;j < SIZE; j++) {
44  c = fgetc(fp);
45  space[i][j] = c;
46  }
47 
48  fclose(fp);
49 }
#define SIZE
Definition: jacobi.c:4
float_t space[SIZE][SIZE]
Definition: jacobi.c:7
#define exit(code)
Definition: misc-local.h:54
int printf()

References exit, printf(), SIZE, and space.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jacobi()

void jacobi ( )

Use 2 array in flip-flop to have dataparallel forall semantics. I could use also a flip-flop dimension instead...

Definition at line 74 of file jacobi.c.

74  {
75  int i, j;
76 
77  /* Use 2 array in flip-flop to have dataparallel forall semantics. I
78  could use also a flip-flop dimension instead... */
79  kernel1:
80  for(i = 1;i < SIZE - 1; i++)
81  for(j = 1;j < SIZE - 1; j++) {
82  save[i][j] = 0.25*(space[i - 1][j] + space[i + 1][j]
83  + space[i][j - 1] + space[i][j + 1]);
84  }
85  for(i = 1;i < SIZE - 1; i++)
86  for(j = 1;j < SIZE - 1; j++) {
87  space[i][j] = 0.25*(save[i - 1][j] + save[i + 1][j]
88  + save[i][j - 1] + save[i][j + 1]);
89  }
90 }
float_t save[SIZE][SIZE]
Definition: jacobi.c:9

References save, SIZE, and space.

Referenced by main().

+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 93 of file jacobi.c.

93  {
94  int t;
95 
96  if (argc != 2) {
97  fprintf(stderr,
98  "%s needs only one argument that is the PGM image input file\n",
99  argv[0]);
100  exit(1);
101  }
102  get_data(argv[1]);
103 
104  for(t = 0; t < T; t++)
105  jacobi();
106 
107  write_data("output.pgm");
108 
109  return 0;
110 }
#define T
Definition: jacobi.c:5
void get_data(char filename[])
Definition: jacobi.c:11
void jacobi()
Definition: jacobi.c:74
void write_data(char filename[])
Definition: jacobi.c:52
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References exit, fprintf(), get_data(), jacobi(), T, and write_data().

+ Here is the call graph for this function:

◆ write_data()

void write_data ( char  filename[])

Write the PGM header:

Definition at line 52 of file jacobi.c.

52  {
53  int i,j;
54  unsigned char c;
55  FILE *fp;
56 
57  if ((fp = fopen(filename, "w")) == NULL) {
58  perror("Error opening file");
59  exit(2);
60  }
61 
62  /* Write the PGM header: */
63  fprintf(fp,"P5\n%d %d\n255\n", SIZE, SIZE);
64 
65  for(i = 0;i < SIZE; i++)
66  for(j = 0;j < SIZE; j++) {
67  c = space[i][j];
68  fputc(c, fp);
69  }
70  fclose(fp);
71 }

References exit, fprintf(), SIZE, and space.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ save

float_t save[SIZE][SIZE]

Definition at line 9 of file jacobi.c.

Referenced by generate_simd_code(), gfc2pips_computeEquiv(), and jacobi().

◆ space