read-dragonfly-sample.c 4.19 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
#define RADIX 8
8 9 10 11 12 13 14 15 16 17 18 19

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;
};

20 21 22
struct dfly_rtr_sample
{
    uint64_t router_id;
23 24
    double busy_time[RADIX];
    int64_t link_traffic[RADIX];
25 26 27
    double end_time;
};

28
static struct dfly_samples * event_array = NULL;
29
static struct dfly_rtr_sample * r_event_array = NULL;
30 31 32 33 34

int main( int argc, char** argv )
{
   int my_rank;
   int size;
35
   int i = 0, j = 0;
36
   /*int radix = atoi(argv[1]);
37 38 39 40 41
   if(!radix)
   {
        printf("\n Router radix should be specified ");
        MPI_Finalize();
        return -1;
42
   }*/
43

44
   printf("\n Router radix %d ", RADIX );
45 46 47 48 49 50
   MPI_Init(&argc, &argv);
   MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
   MPI_Comm_size(MPI_COMM_WORLD, &size);

   FILE* pFile;
   FILE* writeFile;
51
   FILE* writeRouterFile;
52 53 54 55

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

56
   sprintf(buffer_read, "dragonfly-cn-sampling-%d.bin", my_rank);
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
   pFile = fopen(buffer_read, "r+");

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

   sprintf(buffer_write, "dragonfly-write-log.%d", my_rank);
   writeFile = fopen(buffer_write, "w+");

   if(pFile == NULL || writeFile == NULL)
   {
	fputs("\n File error ", stderr);
	return -1;
   }
   fseek(pFile, 0L, SEEK_SET);
   fread(event_array, sizeof(struct dfly_samples), in_sz / sizeof(struct dfly_samples), pFile);
   fprintf(writeFile, " Rank ID \t Finished chunks \t Data size \t Finished hops \t Time spent \t Busy time \t  Sample end time");
   for(i = 0; i < in_sz / sizeof(struct dfly_samples); i++)
   {
    fprintf(writeFile, "\n %ld \t %ld \t %ld \t %lf \t %lf \t %lf \t %lf ", event_array[i].terminal_id,
                                                               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, 
                                                               event_array[i].end_time);
   }
    fclose(pFile);
    fclose(writeFile);
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

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

    sprintf(buffer_rtr_read, "dragonfly-router-sampling-%d.bin", my_rank);
    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);

102
    int sample_size = sizeof(struct dfly_rtr_sample);
103
    sprintf(buffer_rtr_write, "dragonfly-rtr-write-log.%d", my_rank);
104
    writeRouterFile = fopen(buffer_rtr_write, "w+");
105

106
    if(writeRouterFile == NULL || pFile == NULL)
107 108 109 110 111 112 113
    {
        fputs("\n File error ", stderr);
        MPI_Finalize();
        return -1;
    }
    fseek(pFile, 0L, SEEK_SET);
    fread(r_event_array, sample_size, in_sz_rt / sample_size, pFile); 
114 115
    fprintf(writeRouterFile, "\n Router ID \t Busy time per channel \t Link traffic per channel \t Sample end time ");
    printf("\n Sample size %d in_sz_rt %ld ", in_sz_rt / sample_size, in_sz_rt);
116 117
    for(i = 0; i < in_sz_rt / sample_size; i++)
    {
118 119
        //printf("\n %ld ", r_event_array[i].router_id);
        fprintf(writeRouterFile, "\n %ld ", r_event_array[i].router_id);
120
        
121
        for(j = 0; j < RADIX; j++ )
122
        {
123 124
            //printf("\n %lf ", r_event_array[i].busy_time[j]);
            fprintf(writeRouterFile, " %lf ", r_event_array[i].busy_time[j]);
125 126
        }
        
127 128
        for(j = 0; j < RADIX; j++ )
            fprintf(writeRouterFile, " %ld ", r_event_array[i].link_traffic[j]);
129
        
130
        fprintf(writeRouterFile, "\n %lf ", r_event_array[i].end_time);
131 132
    }
    fclose(pFile);
133
    fclose(writeRouterFile);
134 135
    MPI_Finalize();
}