diff options
author | Birte Kristina Friesel <birte.friesel@uos.de> | 2025-01-16 08:04:02 +0100 |
---|---|---|
committer | Birte Kristina Friesel <birte.friesel@uos.de> | 2025-01-16 08:04:02 +0100 |
commit | 4afee0981b81b09104bba9745d09795b85957f27 (patch) | |
tree | 90d41a977613b983c9bec29c10956d5af20dad24 /BFS/support | |
parent | f0ec6cec9304ca0dd558cf8ec5777d0bb2da4307 (diff) |
BFS: indent -linux
Diffstat (limited to 'BFS/support')
-rw-r--r-- | BFS/support/common.h | 23 | ||||
-rw-r--r-- | BFS/support/graph.h | 195 | ||||
-rw-r--r-- | BFS/support/params.h | 81 | ||||
-rw-r--r-- | BFS/support/timer.h | 28 | ||||
-rw-r--r-- | BFS/support/utils.h | 1 |
5 files changed, 178 insertions, 150 deletions
diff --git a/BFS/support/common.h b/BFS/support/common.h index ced324c..5f2aa0d 100644 --- a/BFS/support/common.h +++ b/BFS/support/common.h @@ -9,18 +9,17 @@ #define isSet(val, idx) ((val) & (1 << (idx))) struct DPUParams { - uint32_t dpuNumNodes; /* The number of nodes assigned to this DPU */ - uint32_t numNodes; /* Total number of nodes in the graph */ - uint32_t dpuStartNodeIdx; /* The index of the first node assigned to this DPU */ - uint32_t dpuNodePtrsOffset; /* Offset of the node pointers */ - uint32_t level; /* The current BFS level */ - uint32_t dpuNodePtrs_m; - uint32_t dpuNeighborIdxs_m; - uint32_t dpuNodeLevel_m; - uint32_t dpuVisited_m; - uint32_t dpuCurrentFrontier_m; - uint32_t dpuNextFrontier_m; + uint32_t dpuNumNodes; /* The number of nodes assigned to this DPU */ + uint32_t numNodes; /* Total number of nodes in the graph */ + uint32_t dpuStartNodeIdx; /* The index of the first node assigned to this DPU */ + uint32_t dpuNodePtrsOffset; /* Offset of the node pointers */ + uint32_t level; /* The current BFS level */ + uint32_t dpuNodePtrs_m; + uint32_t dpuNeighborIdxs_m; + uint32_t dpuNodeLevel_m; + uint32_t dpuVisited_m; + uint32_t dpuCurrentFrontier_m; + uint32_t dpuNextFrontier_m; }; #endif - diff --git a/BFS/support/graph.h b/BFS/support/graph.h index f89ff5c..2a19f67 100644 --- a/BFS/support/graph.h +++ b/BFS/support/graph.h @@ -9,108 +9,125 @@ #include "utils.h" struct COOGraph { - uint32_t numNodes; - uint32_t numEdges; - uint32_t* nodeIdxs; - uint32_t* neighborIdxs; + uint32_t numNodes; + uint32_t numEdges; + uint32_t *nodeIdxs; + uint32_t *neighborIdxs; }; struct CSRGraph { - uint32_t numNodes; - uint32_t numEdges; - uint32_t* nodePtrs; - uint32_t* neighborIdxs; + uint32_t numNodes; + uint32_t numEdges; + uint32_t *nodePtrs; + uint32_t *neighborIdxs; }; -static struct COOGraph readCOOGraph(const char* fileName) { - - struct COOGraph cooGraph; - - // Initialize fields - FILE* fp = fopen(fileName, "r"); - uint32_t numNodes, numCols; - assert(fscanf(fp, "%u", &numNodes)); - assert(fscanf(fp, "%u", &numCols)); - if(numNodes == numCols) { - cooGraph.numNodes = numNodes; - } else { - PRINT_WARNING(" Adjacency matrix is not square. Padding matrix to be square."); - cooGraph.numNodes = (numNodes > numCols)? numNodes : numCols; - } - if(cooGraph.numNodes%64 != 0) { - PRINT_WARNING(" Adjacency matrix dimension is %u which is not a multiple of 64 nodes.", cooGraph.numNodes); - cooGraph.numNodes += (64 - cooGraph.numNodes%64); - PRINT_WARNING(" Padding to %u which is a multiple of 64 nodes.", cooGraph.numNodes); - } - assert(fscanf(fp, "%u", &cooGraph.numEdges)); - cooGraph.nodeIdxs = (uint32_t*) malloc(cooGraph.numEdges*sizeof(uint32_t)); - cooGraph.neighborIdxs = (uint32_t*) malloc(cooGraph.numEdges*sizeof(uint32_t)); - - // Read the neighborIdxs - for(uint32_t edgeIdx = 0; edgeIdx < cooGraph.numEdges; ++edgeIdx) { - uint32_t nodeIdx; - assert(fscanf(fp, "%u", &nodeIdx)); - cooGraph.nodeIdxs[edgeIdx] = nodeIdx; - uint32_t neighborIdx; - assert(fscanf(fp, "%u", &neighborIdx)); - cooGraph.neighborIdxs[edgeIdx] = neighborIdx; - } - - return cooGraph; +static struct COOGraph readCOOGraph(const char *fileName) +{ + + struct COOGraph cooGraph; + + // Initialize fields + FILE *fp = fopen(fileName, "r"); + uint32_t numNodes, numCols; + assert(fscanf(fp, "%u", &numNodes)); + assert(fscanf(fp, "%u", &numCols)); + if (numNodes == numCols) { + cooGraph.numNodes = numNodes; + } else { + PRINT_WARNING + (" Adjacency matrix is not square. Padding matrix to be square."); + cooGraph.numNodes = (numNodes > numCols) ? numNodes : numCols; + } + if (cooGraph.numNodes % 64 != 0) { + PRINT_WARNING + (" Adjacency matrix dimension is %u which is not a multiple of 64 nodes.", + cooGraph.numNodes); + cooGraph.numNodes += (64 - cooGraph.numNodes % 64); + PRINT_WARNING + (" Padding to %u which is a multiple of 64 nodes.", + cooGraph.numNodes); + } + assert(fscanf(fp, "%u", &cooGraph.numEdges)); + cooGraph.nodeIdxs = + (uint32_t *) malloc(cooGraph.numEdges * sizeof(uint32_t)); + cooGraph.neighborIdxs = + (uint32_t *) malloc(cooGraph.numEdges * sizeof(uint32_t)); + + // Read the neighborIdxs + for (uint32_t edgeIdx = 0; edgeIdx < cooGraph.numEdges; ++edgeIdx) { + uint32_t nodeIdx; + assert(fscanf(fp, "%u", &nodeIdx)); + cooGraph.nodeIdxs[edgeIdx] = nodeIdx; + uint32_t neighborIdx; + assert(fscanf(fp, "%u", &neighborIdx)); + cooGraph.neighborIdxs[edgeIdx] = neighborIdx; + } + + return cooGraph; } -static void freeCOOGraph(struct COOGraph cooGraph) { - free(cooGraph.nodeIdxs); - free(cooGraph.neighborIdxs); +static void freeCOOGraph(struct COOGraph cooGraph) +{ + free(cooGraph.nodeIdxs); + free(cooGraph.neighborIdxs); } -static struct CSRGraph coo2csr(struct COOGraph cooGraph) { - - struct CSRGraph csrGraph; - - // Initialize fields - csrGraph.numNodes = cooGraph.numNodes; - csrGraph.numEdges = cooGraph.numEdges; - csrGraph.nodePtrs = (uint32_t*) calloc(ROUND_UP_TO_MULTIPLE_OF_2(csrGraph.numNodes + 1), sizeof(uint32_t)); - csrGraph.neighborIdxs = (uint32_t*)malloc(ROUND_UP_TO_MULTIPLE_OF_8(csrGraph.numEdges*sizeof(uint32_t))); - - // Histogram nodeIdxs - for(uint32_t i = 0; i < cooGraph.numEdges; ++i) { - uint32_t nodeIdx = cooGraph.nodeIdxs[i]; - csrGraph.nodePtrs[nodeIdx]++; - } - - // Prefix sum nodePtrs - uint32_t sumBeforeNextNode = 0; - for(uint32_t nodeIdx = 0; nodeIdx < csrGraph.numNodes; ++nodeIdx) { - uint32_t sumBeforeNode = sumBeforeNextNode; - sumBeforeNextNode += csrGraph.nodePtrs[nodeIdx]; - csrGraph.nodePtrs[nodeIdx] = sumBeforeNode; - } - csrGraph.nodePtrs[csrGraph.numNodes] = sumBeforeNextNode; - - // Bin the neighborIdxs - for(uint32_t i = 0; i < cooGraph.numEdges; ++i) { - uint32_t nodeIdx = cooGraph.nodeIdxs[i]; - uint32_t neighborListIdx = csrGraph.nodePtrs[nodeIdx]++; - csrGraph.neighborIdxs[neighborListIdx] = cooGraph.neighborIdxs[i]; - } - - // Restore nodePtrs - for(uint32_t nodeIdx = csrGraph.numNodes - 1; nodeIdx > 0; --nodeIdx) { - csrGraph.nodePtrs[nodeIdx] = csrGraph.nodePtrs[nodeIdx - 1]; - } - csrGraph.nodePtrs[0] = 0; - - return csrGraph; +static struct CSRGraph coo2csr(struct COOGraph cooGraph) +{ + + struct CSRGraph csrGraph; + + // Initialize fields + csrGraph.numNodes = cooGraph.numNodes; + csrGraph.numEdges = cooGraph.numEdges; + csrGraph.nodePtrs = + (uint32_t *) + calloc(ROUND_UP_TO_MULTIPLE_OF_2(csrGraph.numNodes + 1), + sizeof(uint32_t)); + csrGraph.neighborIdxs = + (uint32_t *) + malloc(ROUND_UP_TO_MULTIPLE_OF_8 + (csrGraph.numEdges * sizeof(uint32_t))); + + // Histogram nodeIdxs + for (uint32_t i = 0; i < cooGraph.numEdges; ++i) { + uint32_t nodeIdx = cooGraph.nodeIdxs[i]; + csrGraph.nodePtrs[nodeIdx]++; + } + + // Prefix sum nodePtrs + uint32_t sumBeforeNextNode = 0; + for (uint32_t nodeIdx = 0; nodeIdx < csrGraph.numNodes; ++nodeIdx) { + uint32_t sumBeforeNode = sumBeforeNextNode; + sumBeforeNextNode += csrGraph.nodePtrs[nodeIdx]; + csrGraph.nodePtrs[nodeIdx] = sumBeforeNode; + } + csrGraph.nodePtrs[csrGraph.numNodes] = sumBeforeNextNode; + + // Bin the neighborIdxs + for (uint32_t i = 0; i < cooGraph.numEdges; ++i) { + uint32_t nodeIdx = cooGraph.nodeIdxs[i]; + uint32_t neighborListIdx = csrGraph.nodePtrs[nodeIdx]++; + csrGraph.neighborIdxs[neighborListIdx] = + cooGraph.neighborIdxs[i]; + } + + // Restore nodePtrs + for (uint32_t nodeIdx = csrGraph.numNodes - 1; nodeIdx > 0; --nodeIdx) { + csrGraph.nodePtrs[nodeIdx] = csrGraph.nodePtrs[nodeIdx - 1]; + } + csrGraph.nodePtrs[0] = 0; + + return csrGraph; } -static void freeCSRGraph(struct CSRGraph csrGraph) { - free(csrGraph.nodePtrs); - free(csrGraph.neighborIdxs); +static void freeCSRGraph(struct CSRGraph csrGraph) +{ + free(csrGraph.nodePtrs); + free(csrGraph.neighborIdxs); } #endif - diff --git a/BFS/support/params.h b/BFS/support/params.h index 960a0d0..f9169bc 100644 --- a/BFS/support/params.h +++ b/BFS/support/params.h @@ -5,54 +5,63 @@ #include "common.h" #include "utils.h" -static void usage() { - PRINT( "\nUsage: ./program [options]" - "\n" - "\nBenchmark-specific options:" - "\n -f <F> input matrix file name (default=data/roadNet-CA.txt)" - "\n" - "\nGeneral options:" - "\n -v <V> verbosity" - "\n -h help" - "\n\n"); +static void usage() +{ + PRINT("\nUsage: ./program [options]" + "\n" + "\nBenchmark-specific options:" + "\n -f <F> input matrix file name (default=data/roadNet-CA.txt)" + "\n" + "\nGeneral options:" + "\n -v <V> verbosity" "\n -h help" "\n\n"); } typedef struct Params { - const char* fileName; - unsigned int verbosity; + const char *fileName; + unsigned int verbosity; #if NUMA - struct bitmask* bitmask_in; - int numa_node_cpu; + struct bitmask *bitmask_in; + int numa_node_cpu; #endif } Params; -static struct Params input_params(int argc, char **argv) { - struct Params p; - p.fileName = "data/roadNet-CA.txt"; - p.verbosity = 0; +static struct Params input_params(int argc, char **argv) +{ + struct Params p; + p.fileName = "data/roadNet-CA.txt"; + p.verbosity = 0; #if NUMA - p.bitmask_in = NULL; - p.numa_node_cpu = -1; + p.bitmask_in = NULL; + p.numa_node_cpu = -1; #endif - int opt; - while((opt = getopt(argc, argv, "f:v:hA:C:")) >= 0) { - switch(opt) { - case 'f': p.fileName = optarg; break; - case 'v': p.verbosity = atoi(optarg); break; + int opt; + while ((opt = getopt(argc, argv, "f:v:hA:C:")) >= 0) { + switch (opt) { + case 'f': + p.fileName = optarg; + break; + case 'v': + p.verbosity = atoi(optarg); + break; #if NUMA - case 'A': p.bitmask_in = numa_parse_nodestring(optarg); break; - case 'C': p.numa_node_cpu = atoi(optarg); break; + case 'A': + p.bitmask_in = numa_parse_nodestring(optarg); + break; + case 'C': + p.numa_node_cpu = atoi(optarg); + break; #endif - case 'h': usage(); exit(0); - default: - PRINT_ERROR("Unrecognized option!"); - usage(); - exit(0); - } - } + case 'h': + usage(); + exit(0); + default: + PRINT_ERROR("Unrecognized option!"); + usage(); + exit(0); + } + } - return p; + return p; } #endif - diff --git a/BFS/support/timer.h b/BFS/support/timer.h index 466ad95..63b5567 100644 --- a/BFS/support/timer.h +++ b/BFS/support/timer.h @@ -6,22 +6,26 @@ #include <sys/time.h> typedef struct Timer { - struct timeval startTime[8]; - struct timeval stopTime[8]; - double time[8]; + struct timeval startTime[8]; + struct timeval stopTime[8]; + double time[8]; } Timer; -static void startTimer(Timer *timer, int i, int rep) { - if(rep == 0) { - timer->time[i] = 0.0; - } - gettimeofday(&timer->startTime[i], NULL); +static void startTimer(Timer *timer, int i, int rep) +{ + if (rep == 0) { + timer->time[i] = 0.0; + } + gettimeofday(&timer->startTime[i], NULL); } -static void stopTimer(Timer *timer, int i) { - gettimeofday(&timer->stopTime[i], NULL); - timer->time[i] += (timer->stopTime[i].tv_sec - timer->startTime[i].tv_sec) * 1000000.0 + - (timer->stopTime[i].tv_usec - timer->startTime[i].tv_usec); +static void stopTimer(Timer *timer, int i) +{ + gettimeofday(&timer->stopTime[i], NULL); + timer->time[i] += + (timer->stopTime[i].tv_sec - + timer->startTime[i].tv_sec) * 1000000.0 + + (timer->stopTime[i].tv_usec - timer->startTime[i].tv_usec); } #endif diff --git a/BFS/support/utils.h b/BFS/support/utils.h index ddb1e2c..ccd8fbd 100644 --- a/BFS/support/utils.h +++ b/BFS/support/utils.h @@ -8,4 +8,3 @@ #define PRINT(fmt, ...) printf(fmt "\n", ##__VA_ARGS__) #endif - |