Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/wikka.php on line 315 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/libs/Wakka.class.php on line 176 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/libs/Wakka.class.php on line 463 Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/demetres/public_html/didattica/ae/wikka.php on line 120 Deprecated: Function ereg() is deprecated in /home/demetres/public_html/didattica/ae/libs/Wakka.class.php on line 648 Ingegneria degli Algoritmi: Prestazioni accesso casuale a file

Ingegneria degli Algoritmi

Corso di Laurea in Ingegneria Informatica e Automatica - A.A. 2014-2015

HomePage | Avvisi | Diario lezioni | Programma | Materiale didattico | Esami | Forum | Login
Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/safehtml.php on line 308 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 159 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 161 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 162 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 163 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 165 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 166 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 167 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 243 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 250 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 259 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 266 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 273 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 280 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 467 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 469 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 471

Prestazioni accesso casuale a file


Programma di test per l'accesso casuale a un file:

RandFileScan.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

/* type of file items */
typedef unsigned long ItemType;

int main(int argc, char** argv){

    FILE* f;
    long long i, N, R;

    /* check command line parameters */
    if (argc < 3) exit(printf("Usage: ./RandFileScan fileName numReads\n"));

    /* convert number of accesses from string to integer format */
    R = atoll(argv[2]);
   
    /* open file for reading */
    f = fopen(argv[1], "r");
    if (f == NULL) exit(printf("can't open file %s\n", argv[1]));

    /* compute number N of elements in the file */
    fseeko(f, 0LL, SEEK_END);
    N = ftello(f)/sizeof(ItemType);

    printf("file offset: %d bit\n", (int)sizeof(off_t)*8);
    printf("make %lld random accesses to file of %lld 32 bit integers...\n", R, N);

    /* init pseudo-random generator seed */
    srand(time(NULL));

    /* make R random file accesses */
    for (i=0; i<R; ++i) {
        ItemType val;
        long long j = (long long)(N*((double)rand()/RAND_MAX));
        fseeko(f, j*sizeof(ItemType), SEEK_SET);
        fread(&val, sizeof(ItemType), 1, f);
    }

    fclose(f);
}


Analisi sperimentale

Obiettivo: stimare il tempo di lettura casuale di 10000 interi a 32 bit in un file di 2 miliardi di interi a 32 bit (7.45 GB)

Piattaforma:


Esperimento:

> gcc -o RandFileScan RandFileScan.c
> time ./RandFileScan large.dat 10000
file offset: 64 bit
make 10000 random accesses to file of 2000000000 32 bit integers...

real	1m58.419s
user	0m0.303s
sys	0m1.671s
>


Risultati:

Il tempo richiesto per leggere in modo casuale 10000 interi a 32 bit in un file di 2 miliardi di interi a 32 bit (7.45 GB) è di 1 minuti e 58.419 secondi = 118.419 secondi, cioè 11.8 millisecondi per intero, ovvero un throughput di circa 337.8 byte/sec = 0.0003 MB/sec.

L'uso della CPU durante l'esecuzione del programma si attesta intorno all'1.6%, contro il 77% dell'accesso sequenziale.

Il throughput per l'accesso sequenziale sulla stessa macchina è di circa 31.8 MB/sec, circa 100000 volte più alto!

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.3
Page was generated in 0.0508 seconds