read-dragonfly-sample.c 6.85 KB
Newer Older
1 2 3 4 5 6
/* usage mpirun -np n ./read_file_io 
n is the number of input bgp-log files */
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <mpi.h>
7
#include <assert.h>
8
#define RADIX 16
9 10 11 12 13 14 15 16 17 18

struct dfly_samples
{
   uint64_t terminal_id;
   long fin_chunks_sample;
   long data_size_sample;
   double fin_hops_sample;
   double fin_chunks_time;
   double busy_time_sample;
   double end_time;
19 20
   long fwd_events;
   long rev_events;
21 22
};

23 24 25
struct dfly_rtr_sample
{
    uint64_t router_id;
26 27
    double busy_time[RADIX];
    int64_t link_traffic[RADIX];
28
    double end_time;
29 30
    long fwd_events;
    long rev_events;
31 32
};

33 34 35
struct mpi_workload_sample
{
    int nw_id;
36
    int app_id;
37 38 39 40 41
    unsigned long num_sends_sample;
    unsigned long num_bytes_sample;
    unsigned long num_waits_sample;
    double sample_end_time;
};
42
static struct dfly_samples * event_array = NULL;
43
static struct dfly_rtr_sample * r_event_array = NULL;
44
static struct mpi_workload_sample * mpi_event_array = NULL;
45 46 47 48 49

int main( int argc, char** argv )
{
   int my_rank;
   int size;
50
   int i = 0, j = 0;
51 52
   /*int RADIX = atoi(argv[1]);
   if(!RADIX)
53
   {
54
        printf("\n Router RADIX should be specified ");
55 56
        MPI_Finalize();
        return -1;
57
   }*/
58 59 60 61 62 63 64

   MPI_Init(&argc, &argv);
   MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
   MPI_Comm_size(MPI_COMM_WORLD, &size);

   FILE* pFile;
   FILE* writeFile;
65
   FILE* writeRouterFile;
66 67 68 69

   char buffer_read[64];
   char buffer_write[64];

70
   sprintf(buffer_read, "dragonfly-cn-sampling-%d.bin", my_rank);
71 72 73 74 75 76 77
   pFile = fopen(buffer_read, "r+");

   struct stat st;
   stat(buffer_read, &st);
   long in_sz = st.st_size;
   event_array = malloc(in_sz);

78
   sprintf(buffer_write, "dragonfly-write-log-%d.dat", my_rank);
79
   writeFile = fopen(buffer_write, "w");
80 81 82 83 84 85

   if(pFile == NULL || writeFile == NULL)
   {
	fputs("\n File error ", stderr);
	return -1;
   }
86 87 88 89 90 91 92 93 94
   if(my_rank == 0)
   {
        char meta_filename[128];
        sprintf(meta_filename, "dragonfly-write-log.meta");

        FILE * fp_meta = fopen(meta_filename, "w+");
        fprintf(fp_meta, "Rank_ID num_finished_chunks data_size_finished(bytes) finished_hops time_spent(ns) busy_time(ns) num_fwd_events num_rev_events sample_end_time(ns)");
        fclose(fp_meta);
   }
95 96 97 98
   fseek(pFile, 0L, SEEK_SET);
   fread(event_array, sizeof(struct dfly_samples), in_sz / sizeof(struct dfly_samples), pFile);
   for(i = 0; i < in_sz / sizeof(struct dfly_samples); i++)
   {
99
    printf("\n Terminal id %ld ", event_array[i].terminal_id);
100
    fprintf(writeFile, "%ld %ld %ld %lf %lf %lf %ld %ld %lf \n", event_array[i].terminal_id,
101 102 103 104 105
                                                               event_array[i].fin_chunks_sample,
                                                               event_array[i].data_size_sample,
                                                               event_array[i].fin_hops_sample, 
                                                               event_array[i].fin_chunks_time, 
                                                               event_array[i].busy_time_sample, 
106 107
                                                               event_array[i].fwd_events,
                                                               event_array[i].rev_events,
108 109 110 111
                                                               event_array[i].end_time);
   }
    fclose(pFile);
    fclose(writeFile);
112 113 114 115 116 117

    printf("\n Now reading router file ");
    /* Now read the router sampling file */
    char buffer_rtr_read[64];
    char buffer_rtr_write[64];

118
    sprintf(buffer_rtr_read, "dragonfly-router-sampling-%d.bin", my_rank);
119 120 121 122 123 124 125 126
    pFile = fopen(buffer_rtr_read, "r+");

    struct stat st2;
    stat(buffer_rtr_read, &st2);
    long in_sz_rt = st2.st_size;

    r_event_array = malloc(in_sz_rt);

127
    int sample_size = sizeof(struct dfly_rtr_sample);
128
    sprintf(buffer_rtr_write, "dragonfly-rtr-write-%d.dat", my_rank);
129
    writeRouterFile = fopen(buffer_rtr_write, "w");
130

131
    if(writeRouterFile == NULL || pFile == NULL)
132 133 134 135 136 137
    {
        fputs("\n File error ", stderr);
        MPI_Finalize();
        return -1;
    }
    fseek(pFile, 0L, SEEK_SET);
138 139 140 141 142 143 144 145 146 147 148
   
    if(my_rank == 0)
    {
        char rtr_meta_filename[128];
        sprintf(rtr_meta_filename, "dragonfly-rtr-write-log.meta");

        FILE * fp_rtr_meta = fopen(rtr_meta_filename, "w+");
        fprintf(fp_rtr_meta, "%d entries for busy time and link traffic \n", RADIX);
        fprintf(fp_rtr_meta, "Format: Router_ID Busy_time_per_channel(ns) Link_traffic_per_channel(ns) Sample_end_time(ns) fwd_events reverse_events");
        fclose(fp_rtr_meta);
   }
149
    fread(r_event_array, sample_size, in_sz_rt / sample_size, pFile); 
150
    //printf("\n Sample size %d in_sz_rt %ld ", in_sz_rt / sample_size, in_sz_rt);
151 152
    for(i = 0; i < in_sz_rt / sample_size; i++)
    {
153
        //printf("\n %ld ", r_event_array[i].router_id);
154
        fprintf(writeRouterFile, "%ld ", r_event_array[i].router_id);
155
        
156
        for(j = 0; j < RADIX; j++ )
157
        {
158 159
            //printf("\n %lf ", r_event_array[i].busy_time[j]);
            fprintf(writeRouterFile, " %lf ", r_event_array[i].busy_time[j]);
160 161
        }
        
162
        for(j = 0; j < RADIX; j++ )
163 164
        {
            //printf("\n link traffic %ld ", r_event_array[i].link_traffic[j]);
165
            fprintf(writeRouterFile, " %ld ", r_event_array[i].link_traffic[j]);
166
        }
167
       fprintf(writeRouterFile, " %lf ", r_event_array[i].end_time);
168 169
        fprintf(writeRouterFile, " %ld ", r_event_array[i].fwd_events);
        fprintf(writeRouterFile, " %ld \n", r_event_array[i].rev_events);
170 171
    }
    fclose(pFile);
172
    fclose(writeRouterFile);
173 174 175 176 177 178 179 180 181 182 183
    
    sprintf(buffer_rtr_read, "mpi-aggregate-logs-%d.bin", my_rank);
    pFile = fopen(buffer_rtr_read, "r+");
    assert(pFile);

    struct stat st3;
    stat(buffer_rtr_read, &st3);
    long in_sz_mpi = st3.st_size;

    mpi_event_array = malloc(in_sz_mpi);
    int mpi_sample_sz = sizeof(struct mpi_workload_sample);
184
    sprintf(buffer_rtr_write, "dragonfly-mpi-write-logs-%d.dat", my_rank);
185 186 187
    writeFile = fopen(buffer_rtr_write, "w+");
    assert(writeFile);

188 189 190 191 192 193 194 195 196
    if(my_rank == 0)
    {
        char ops_meta_filename[128];
        sprintf(ops_meta_filename, "dragonfly-mpi-write-logs.meta");

        FILE * fp_ops_meta = fopen(ops_meta_filename, "w+");
        fprintf(fp_ops_meta, "network_node_id app_id num_sends num_bytes_sent num_waits sample_end_time(ns)");
        fclose(fp_ops_meta);
   }
197 198 199
    fread(mpi_event_array, mpi_sample_sz, in_sz_mpi / mpi_sample_sz, pFile);
    for(i = 0; i < in_sz_mpi / mpi_sample_sz; i++)
    {
200 201 202 203
        fprintf(writeFile, "\n %d %d %lu %lu %lu %lf ",
                mpi_event_array[i].nw_id,
                mpi_event_array[i].app_id,
                mpi_event_array[i].num_sends_sample,
204 205 206 207 208 209 210
                mpi_event_array[i].num_bytes_sample,
                mpi_event_array[i].num_waits_sample,
                mpi_event_array[i].sample_end_time);
    }
    fclose(pFile);
    fclose(writeFile);

211 212
    MPI_Finalize();
}