Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VReo > Reo__Matrix_Mult
diff main.c @ 0:c4b1849c05ef
init add
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Sun, 02 Feb 2014 17:58:41 -0800 |
| parents | |
| children | 1b61e0c00512 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/main.c Sun Feb 02 17:58:41 2014 -0800 1.3 @@ -0,0 +1,109 @@ 1.4 +#include <malloc.h> 1.5 +#include <stdlib.h> 1.6 +#include <PR__include/PR__WL.h> 1.7 + 1.8 +#include "Matrix_Mult.h" 1.9 +#include "Reo__Matrix_Mult/Reo__Matrix_Mult.h" 1.10 + 1.11 +void set_up_performance_counters(); 1.12 + 1.13 +// ============================================================================= 1.14 + 1.15 +int NUM_ITER; 1.16 + 1.17 +MatrixMultGlobals *globals; 1.18 + 1.19 +int main(int argc, char **argv) 1.20 + { Matrix *leftMatrix, *rightMatrix, *resultMatrix; 1.21 + ParamBag *paramBag; 1.22 + 1.23 + DEBUG__printf(TRUE, "arguments: %s | %s", argv[0], argv[1]); 1.24 + if(argc < 3) {printf("give num iter and path to param file on cmd line\n"); exit(1);} 1.25 + NUM_ITER = atoi(argv[1]); 1.26 + 1.27 + //read parameters, from file whose path is given on command line 1.28 + paramBag = makeParamBag(); 1.29 + readParamFileIntoBag( argv[2], paramBag ); 1.30 + initialize_Input_Matrices_Via( &leftMatrix, &rightMatrix, paramBag ); 1.31 + 1.32 + 1.33 + printf("[reo] Settings: %i workers, %i iterations -- ", NUM_PROD, NUM_ITER); 1.34 + 1.35 + set_up_performance_counters(); 1.36 + 1.37 + PRProcess *matrixMultProcess; 1.38 + PR_Main__start(); 1.39 + PR_Main__set_app_info( "matrix multiply prod cons in Reo" ); 1.40 + 1.41 + PR_Main__set_input_info( getParamFromBag( "inputInfo", paramBag ) ); 1.42 + 1.43 + params->resultMatrix = malloc( numRows * numCols * sizeof(double) ); 1.44 + params->workUnits = divideWork( leftInput, rightInput, numUnitsToMake ); 1.45 + 1.46 + matrixMultProcess = PR_Main__create_process(&matrix_mult__seed_Fn, params); 1.47 + 1.48 + PR_Main__wait_for_process_to_end(matrixMultProcess); 1.49 + PR__Main__wait_for_all_activity_to_end(); 1.50 + fflush(stdout); 1.51 + PR_Main__shutdown(); 1.52 + 1.53 + exit(0); 1.54 + } 1.55 + 1.56 +// ============================================================================= 1.57 + 1.58 +/*Initializes the performance counters, and opens the file descriptors used 1.59 + * to read from the performance counters 1.60 + */ 1.61 +void set_up_performance_counters() { 1.62 + int i; 1.63 + 1.64 +#ifdef MEASURE_PERF 1.65 + //setup performance counters 1.66 + struct perf_event_attr hw_event; 1.67 + memset(&hw_event,0,sizeof(hw_event)); 1.68 + hw_event.type = PERF_TYPE_HARDWARE; 1.69 + hw_event.size = sizeof(hw_event); 1.70 + hw_event.disabled = 0; 1.71 + hw_event.freq = 0; 1.72 + hw_event.inherit = 1; /* children inherit it */ 1.73 + hw_event.pinned = 1; /* must always be on PMU */ 1.74 + hw_event.exclusive = 0; /* only group on PMU */ 1.75 + hw_event.exclude_user = 0; /* don't count user */ 1.76 + hw_event.exclude_kernel = 1; /* ditto kernel */ 1.77 + hw_event.exclude_hv = 1; /* ditto hypervisor */ 1.78 + hw_event.exclude_idle = 1; /* don't count when idle */ 1.79 + hw_event.mmap = 0; /* include mmap data */ 1.80 + hw_event.comm = 0; /* include comm data */ 1.81 + 1.82 + for( i = 0; i < NUM_CORES; i++ ) 1.83 + { 1.84 + hw_event.config = PERF_COUNT_HW_CPU_CYCLES; //cycles 1.85 + cycles_counter_fd[i] = syscall(__NR_perf_event_open, &hw_event, 1.86 + 0,//pid_t pid, 1.87 + i,//int cpu, 1.88 + -1,//int group_fd, 1.89 + 0//unsigned long flags 1.90 + ); 1.91 + if (cycles_counter_fd[i]<0) { 1.92 + fprintf(stderr,"On core %d: ",i); 1.93 + perror("Failed to open cycles counter"); 1.94 + } 1.95 + } 1.96 + 1.97 + int cycles_counter_main_fd; 1.98 + hw_event.config = PERF_COUNT_HW_CPU_CYCLES; //cycles 1.99 + hw_event.exclude_kernel=0; 1.100 + cycles_counter_main_fd = syscall(__NR_perf_event_open, &hw_event, 1.101 + 0,//pid_t pid, 1.102 + -1,//int cpu, 1.103 + -1,//int group_fd, 1.104 + 0//unsigned long flags 1.105 + ); 1.106 + if (cycles_counter_main_fd<0) { 1.107 + perror("Failed to open main cycles counter"); 1.108 + } 1.109 + 1.110 +#endif 1.111 +} 1.112 +
