venerdì 28 settembre 2012

Intel C Compiler vs GCC in Mandelbrot

Ho provato a verificare la differenza tra Gcc ed il compilatore Intel C++ (icc) per quanto riguarda la velocita' e l'ottimizzazione dei calcoli
Per fare cio' e' stato impiegato il programma per generare l'insieme di Mandelbrot gia' presentato in un precedente post usando gli stessi switch di compilazione all'interno del file make



Makefile
------------------------------------------------------
main: mand_sdl.c
    /opt/intel/bin/icc -Wall -O3 mand_sdl.c -o mand_sdl_icc -lSDL
    gcc -Wall -O3 mand_sdl.c -o mand_sdl_gcc -lSDL

------------------------------------------------------

Il programma e' il seguente
 mand_sdl.c
------------------------------------------------------
 #include "SDL/SDL.h"
#include <stdio.h>

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_DEPTH 8

float re_min = -2.0;
float im_min = -1.2;

float re_max = 1.0;
float im_max = 1.2;
int iterazioni = 255;


float a,b;
float x,y,x_new,y_new;

int test;

int k,j,i;

int keypress = 0;


int main() {

SDL_Surface *screen;
Uint8       *p;

float re_factor = (re_max-re_min);
float im_factor = (im_max-im_min);
   
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);

for (i=0;i<SCREEN_HEIGHT;i++)
    {
    for (j=0;j<SCREEN_WIDTH;j++)
        {
        a = re_min+(j*re_factor/SCREEN_WIDTH);  
        b = im_min+(i*im_factor/SCREEN_HEIGHT);
      
        x = 0;
        y = 0;
        test = 0;
      
        for (k=0;k<iterazioni;k++)
            {
            x_new = (x*x)-(y*y)+a;
            y_new = (2*x*y)+b;
            if (((x_new*x_new)+(y_new*y_new))>4)
                {
                test = k;
                p = (Uint8 *)screen->pixels + i * screen->pitch + j * screen->format->BytesPerPixel;
                *p=(k%255);
                break;
                }
            x = x_new;
            y = y_new;
            }
          
        }

    }
SDL_Flip(screen);

printf("Finito\n\r");

SDL_Quit();

return(0);

}


------------------------------------------------------
Per calcolare il tempo di esecuzione e' stato usato il comando time che misura il tempo tra l'inizio e la fine dell'esecuzione

time  mand_sdl_gcc
time mand_sdl_icc

i risultati sono decisamente schiaccianti. Intel vince in velocita'

Intel
Totale 0.974
User   0.624
Sys    0.024

Gcc
Totale 1.325
User   0.948
Sys    0.020


Link al progetto

Nessun commento:

Posta un commento

Retrain Yolo8 con rifiuti su spiaggia

Ho provato a fare il retraining di Yolo 8 con rifiuti spiaggiati usando il dataset al link sottostante  https://universe.roboflow.com/baeula...