OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [remove_cycle/] [agony/] [read.cpp] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
#include "graph.h"
2
#include <map>
3
 
4
typedef std::map<uint32_t, uint32_t> intmap;
5
 
6
void
7
agony::read(FILE *f)
8
{
9
        uint32_t cnt = 0;
10
        uint32_t a, b;
11
        uint32_t ecnt = 0;
12
 
13
        intmap labelmap;
14
 
15
 
16
 
17
        while (fscanf(f, "%d%d", &a, &b) == 2) {
18
                if (labelmap.count(a) == 0)
19
                        labelmap[a] = cnt++;
20
                if (labelmap.count(b) == 0)
21
                        labelmap[b] = cnt++;
22
                ecnt++;
23
        }
24
 
25
        m_nodes.resize(cnt);
26
        m_edges.resize(ecnt);
27
 
28
        for (uint32_t i = 0; i < size(); i++)
29
                m_nodes[i].id = i;
30
 
31
        for (intmap::iterator it = labelmap.begin(); it != labelmap.end(); ++it)
32
                m_nodes[it->second].label = it->first;
33
 
34
        for (uint32_t i = 0; i < m_edges.size(); i++)
35
                m_edges[i].id = i;
36
 
37
        m_graph.reset(cnt, ecnt);
38
 
39
        rewind(f);
40
 
41
        ecnt = 0;
42
        while (fscanf(f, "%d%d", &a, &b) == 2) {
43
                m_graph.bind(ecnt, labelmap[a], labelmap[b]);
44
                ecnt++;
45
        }
46
}
47
 
48
void
49
agony::writeagony(FILE *f)
50
{
51
        intmap ranks;
52
 
53
        for (uint32_t i = 0; i < size(); i++) {
54
                ranks[m_nodes[i].rank] = 0;
55
        }
56
 
57
        uint32_t r = 0;
58
        for (intmap::iterator it = ranks.begin(); it != ranks.end(); ++it)
59
                it->second = r++;
60
 
61
        for (uint32_t i = 0; i < size(); i++) {
62
                fprintf(f, "%d %d\n", m_nodes[i].label, ranks[m_nodes[i].rank]);
63
        }
64
 
65
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.