Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VReo > Reo__Matrix_Mult
view 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 source
1 #include <malloc.h>
2 #include <stdlib.h>
3 #include <PR__include/PR__WL.h>
5 #include "Matrix_Mult.h"
6 #include "Reo__Matrix_Mult/Reo__Matrix_Mult.h"
8 void set_up_performance_counters();
10 // =============================================================================
12 int NUM_ITER;
14 MatrixMultGlobals *globals;
16 int main(int argc, char **argv)
17 { Matrix *leftMatrix, *rightMatrix, *resultMatrix;
18 ParamBag *paramBag;
20 DEBUG__printf(TRUE, "arguments: %s | %s", argv[0], argv[1]);
21 if(argc < 3) {printf("give num iter and path to param file on cmd line\n"); exit(1);}
22 NUM_ITER = atoi(argv[1]);
24 //read parameters, from file whose path is given on command line
25 paramBag = makeParamBag();
26 readParamFileIntoBag( argv[2], paramBag );
27 initialize_Input_Matrices_Via( &leftMatrix, &rightMatrix, paramBag );
30 printf("[reo] Settings: %i workers, %i iterations -- ", NUM_PROD, NUM_ITER);
32 set_up_performance_counters();
34 PRProcess *matrixMultProcess;
35 PR_Main__start();
36 PR_Main__set_app_info( "matrix multiply prod cons in Reo" );
38 PR_Main__set_input_info( getParamFromBag( "inputInfo", paramBag ) );
40 params->resultMatrix = malloc( numRows * numCols * sizeof(double) );
41 params->workUnits = divideWork( leftInput, rightInput, numUnitsToMake );
43 matrixMultProcess = PR_Main__create_process(&matrix_mult__seed_Fn, params);
45 PR_Main__wait_for_process_to_end(matrixMultProcess);
46 PR__Main__wait_for_all_activity_to_end();
47 fflush(stdout);
48 PR_Main__shutdown();
50 exit(0);
51 }
53 // =============================================================================
55 /*Initializes the performance counters, and opens the file descriptors used
56 * to read from the performance counters
57 */
58 void set_up_performance_counters() {
59 int i;
61 #ifdef MEASURE_PERF
62 //setup performance counters
63 struct perf_event_attr hw_event;
64 memset(&hw_event,0,sizeof(hw_event));
65 hw_event.type = PERF_TYPE_HARDWARE;
66 hw_event.size = sizeof(hw_event);
67 hw_event.disabled = 0;
68 hw_event.freq = 0;
69 hw_event.inherit = 1; /* children inherit it */
70 hw_event.pinned = 1; /* must always be on PMU */
71 hw_event.exclusive = 0; /* only group on PMU */
72 hw_event.exclude_user = 0; /* don't count user */
73 hw_event.exclude_kernel = 1; /* ditto kernel */
74 hw_event.exclude_hv = 1; /* ditto hypervisor */
75 hw_event.exclude_idle = 1; /* don't count when idle */
76 hw_event.mmap = 0; /* include mmap data */
77 hw_event.comm = 0; /* include comm data */
79 for( i = 0; i < NUM_CORES; i++ )
80 {
81 hw_event.config = PERF_COUNT_HW_CPU_CYCLES; //cycles
82 cycles_counter_fd[i] = syscall(__NR_perf_event_open, &hw_event,
83 0,//pid_t pid,
84 i,//int cpu,
85 -1,//int group_fd,
86 0//unsigned long flags
87 );
88 if (cycles_counter_fd[i]<0) {
89 fprintf(stderr,"On core %d: ",i);
90 perror("Failed to open cycles counter");
91 }
92 }
94 int cycles_counter_main_fd;
95 hw_event.config = PERF_COUNT_HW_CPU_CYCLES; //cycles
96 hw_event.exclude_kernel=0;
97 cycles_counter_main_fd = syscall(__NR_perf_event_open, &hw_event,
98 0,//pid_t pid,
99 -1,//int cpu,
100 -1,//int group_fd,
101 0//unsigned long flags
102 );
103 if (cycles_counter_main_fd<0) {
104 perror("Failed to open main cycles counter");
105 }
107 #endif
108 }
