test21_iops.c 3.68 KB
Newer Older
Antonio Gomez's avatar
Antonio Gomez committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/***********************************************************************
 *
 * DESCRIPTION :
 *      Test that measures IOPS
 *
 * AUTHOR: Antonio Gomez        START DATE: 5 Feb 18
 *
 */

#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <papyrus/kv.h>
#include <papyrus/mpi.h>
#include <unistd.h>
#include <sys/time.h>

#define PAPYRUSKV_SCRATCH 0

int rank, size, peer;
char name[256];
char *text;
int lenght;
int db;
int ret;

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

    MPI_Init(&argc, &argv);
    //Initialize papyrus
    papyruskv_init(&argc, &argv, "kv_repo");

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
37
38
    if (size<2) {
        printf ("This test needs at least 2 processes\n");
Antonio Gomez's avatar
Antonio Gomez committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
        return 1;
    }

    MPI_Get_processor_name(name, &ret);

    text=(char*) malloc (64*sizeof(char));
    memset(text, '\0', 65);

    peer = rank == size - 1 ? 0 : rank + 1;

    printf("[%s:%d] [%s] [%d/%d]\n", __FILE__, __LINE__, name, rank, size);

    ret = papyruskv_open("TEST_DB", PAPYRUSKV_CREATE | PAPYRUSKV_RELAXED | PAPYRUSKV_RDWR, NULL, &db);
    if (ret != PAPYRUSKV_OK) printf("[%s:%d] ret[%d]\n", __FILE__, __LINE__, ret);
    printf("[%s:%d] db[%d]\n", __FILE__, __LINE__, db);

    papyruskv_consistency (db, PAPYRUSKV_SEQUENTIAL);

    if (rank==0) {
        //Mount the files in the /tmp/test folder as a scratch space (it won't be written back)
Antonio Gomez's avatar
Antonio Gomez committed
59
        ret=papyruskv_mount_file(db, "/home1/05191/agomezig/papyrus/kv/tests/21_iops/test_file", "r", PAPYRUSKV_SCRATCH);
Antonio Gomez's avatar
Antonio Gomez committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

        if (ret != PAPYRUSKV_OK) printf("\n\n[%s:%d] ret[%d]\n\n", __FILE__, __LINE__, ret);
        else printf ("\n\nFile mounted\n\n");
    }
    MPI_Barrier (MPI_COMM_WORLD);
    ret = papyruskv_fence(db, PAPYRUSKV_MEMTABLE);
    if (ret != PAPYRUSKV_OK) printf("[%s:%d] FAILED:ret[%d]\n", __FILE__, __LINE__, ret);
    printf("[%s:%d] FENCE:rank[%d]\n", __FILE__, __LINE__, rank);

    MPI_Barrier (MPI_COMM_WORLD);

    struct timeval tv1, tv2;

    if (rank==0) {
        gettimeofday(&tv1, NULL);
Antonio Gomez's avatar
Antonio Gomez committed
75
76
        for (i=0; i<10000; ++i) {
            ret=papyruskv_fread(db, text, 64, 0, "/home1/05191/agomezig/papyrus/kv/tests/21_iops/test_file");
Antonio Gomez's avatar
Antonio Gomez committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
            if (ret != PAPYRUSKV_OK) {
                printf("\n\n[%s:%d] ret[%d]\n\n", __FILE__, __LINE__, ret);
                break;
            }
            else {
           //     printf ("\n\n[0] Read content: %s\n\n", text);
            }
        }
        gettimeofday(&tv2, NULL);
    }

    MPI_Barrier (MPI_COMM_WORLD);
    if (rank!=0) {
        gettimeofday(&tv1, NULL);
Antonio Gomez's avatar
Antonio Gomez committed
91
92
        for (i=0; i<10000; ++i) {
            ret=papyruskv_fread(db, text, 64, 0, "/home1/05191/agomezig/papyrus/kv/tests/21_iops/test_file");
Antonio Gomez's avatar
Antonio Gomez committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
            if (ret != PAPYRUSKV_OK) {
                printf("\n\n[%s:%d] ret[%d]\n\n", __FILE__, __LINE__, ret);
                break;
            }
            else {
            //    printf ("\n\n[%d] Read content: %s\n\n", rank, text);
            }
        }
        gettimeofday(&tv2, NULL);
    }

    MPI_Barrier (MPI_COMM_WORLD);

    double ellapsed = (double)(tv2.tv_usec - tv1.tv_usec) / 1000000 + (double)(tv2.tv_sec - tv1.tv_sec);


Antonio Gomez's avatar
Antonio Gomez committed
109
    double IOPS = 10000.0/ellapsed;
Antonio Gomez's avatar
Antonio Gomez committed
110

Antonio Gomez's avatar
Antonio Gomez committed
111
    printf ("\nRank [%d] IOPS: %f [ellapsed %f]\n\n", rank, IOPS, ellapsed);
Antonio Gomez's avatar
Antonio Gomez committed
112
113

    if (rank==0) {
Antonio Gomez's avatar
Antonio Gomez committed
114
        ret=papyruskv_fclose(db, "/home1/05191/agomezig/papyrus/kv/tests/21_iops/test_file");
Antonio Gomez's avatar
Antonio Gomez committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
        if (ret != PAPYRUSKV_OK) printf("\n\n[%s:%d] ret[%d]\n\n", __FILE__, __LINE__, ret);
        else printf ("\n\nFile closed\n\n");
    }

    ret = papyruskv_close(db);
    if (ret != PAPYRUSKV_OK) printf("[%s:%d] ret[%d]\n", __FILE__, __LINE__, ret);

    papyruskv_finalize();
    MPI_Finalize();

    free (text);
    return 0;
}