view main.c @ 1:1b61e0c00512

almost working k=3, about to change to k=4
author Sean Halle <seanhalle@yahoo.com>
date Wed, 19 Feb 2014 09:27:10 -0800
parents c4b1849c05ef
children 96deb7b4502e a6b3cab179b1
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;
15 int main(int argc, char **argv)
16 { Matrix *leftMatrix, *rightMatrix, *resultMatrix;
17 ParamBag *paramBag;
18 MatrixMultWorkUnit **workUnits;
19 VPParams *vpParams, **vpParamsArray;
20 // ProdParams *prodParams;
21 // ConsParams *consParams;
22 int32 numUnitsToMake, vpIdx;
23 PRProcess *matrixMultProcess;
25 DEBUG__printf(TRUE, "arguments -- numIter: %s | path: %s", argv[1], argv[2] );
26 if(argc < 3) {printf("give: num iter and path to param file on cmd line\n"); exit(1);}
27 NUM_ITER = atoi(argv[1]);
28 numUnitsToMake = NUM_PROD; //defined by Reo circuit generator
30 printf("[reo] Settings: %i workers, %i iterations | file: %s \n", NUM_PROD, NUM_ITER, argv[2]);
32 set_up_performance_counters();
34 //read parameters, from file whose path is given on command line
35 paramBag = makeParamBag();
36 readParamFileIntoBag( argv[2], paramBag );
37 initialize_Input_Matrices_Via( &leftMatrix, &rightMatrix, paramBag );
40 PR__start();
41 PR__set_app_info( "matrix multiply prod cons in Reo" );
42 ParamStruc *inputInfo = getParamFromBag( "inputInfo", paramBag );
43 PR__set_input_info( inputInfo->strValue );
45 resultMatrix = PR__malloc( sizeof(Matrix) );
46 resultMatrix->array = PR__malloc( leftMatrix->numRows * rightMatrix->numCols * sizeof(double) );
47 resultMatrix->numCols = rightMatrix->numCols;
48 resultMatrix->numRows = leftMatrix->numRows;
49 workUnits = divideWork( leftMatrix, rightMatrix, resultMatrix,
50 numUnitsToMake );
52 /* For now, don't need any params inside producer function other than
53 * the work unit. Also, don't need any params at all inside cons function.
54 * So, just send the array of work units to the seed Fn, which will pass it
55 * along to the create_VP part of circuit creation, which will copy the
56 * elements of the array into the param structs given as initData to the
57 * VPs, as they are created.
58 *Need a dummy work unit added to end of work-unit array, to avoid a seg
59 * fault -- just did a bad hack inside divideWork.
60 //Now, create params struct for each producer -- holds work unit
61 for( vpIdx=0; vpIdx<numUnitsToMake; vpIdx++)
62 {
63 vpParams = PR__malloc( sizeof(VPParams) );
64 prodParams = PR__malloc( sizeof(ProdParams) );
66 vpParams->initData = prodParams;
67 vpParamsArray[vpIdx] = vpParams;
68 }
69 //create params for consumer
71 vpParams = PR__malloc( sizeof(VPParams) );
72 = malloc( sizeof(ProdParams) );
74 vpParams->initData =
75 vpParamsArray[vpIdx] = vpParams; //this last entry is for the consumer
76 */
78 matrixMultProcess = PR__create_process( &matrix_mult__seed_Fn,
79 workUnits );
81 PR__wait_for_process_to_end(matrixMultProcess);
82 PR__wait_for_all_activity_to_end();
83 fflush(stdout);
84 PR__shutdown();
86 exit(0);
87 }
89 // =============================================================================
91 /*Initializes the performance counters, and opens the file descriptors used
92 * to read from the performance counters
93 */
94 void set_up_performance_counters() {
95 int i;
97 #ifdef MEASURE_PERF
98 //setup performance counters
99 struct perf_event_attr hw_event;
100 memset(&hw_event,0,sizeof(hw_event));
101 hw_event.type = PERF_TYPE_HARDWARE;
102 hw_event.size = sizeof(hw_event);
103 hw_event.disabled = 0;
104 hw_event.freq = 0;
105 hw_event.inherit = 1; /* children inherit it */
106 hw_event.pinned = 1; /* must always be on PMU */
107 hw_event.exclusive = 0; /* only group on PMU */
108 hw_event.exclude_user = 0; /* don't count user */
109 hw_event.exclude_kernel = 1; /* ditto kernel */
110 hw_event.exclude_hv = 1; /* ditto hypervisor */
111 hw_event.exclude_idle = 1; /* don't count when idle */
112 hw_event.mmap = 0; /* include mmap data */
113 hw_event.comm = 0; /* include comm data */
115 for( i = 0; i < NUM_CORES; i++ )
116 {
117 hw_event.config = PERF_COUNT_HW_CPU_CYCLES; //cycles
118 cycles_counter_fd[i] = syscall(__NR_perf_event_open, &hw_event,
119 0,//pid_t pid,
120 i,//int cpu,
121 -1,//int group_fd,
122 0//unsigned long flags
123 );
124 if (cycles_counter_fd[i]<0) {
125 fprintf(stderr,"On core %d: ",i);
126 perror("Failed to open cycles counter");
127 }
128 }
130 int cycles_counter_main_fd;
131 hw_event.config = PERF_COUNT_HW_CPU_CYCLES; //cycles
132 hw_event.exclude_kernel=0;
133 cycles_counter_main_fd = syscall(__NR_perf_event_open, &hw_event,
134 0,//pid_t pid,
135 -1,//int cpu,
136 -1,//int group_fd,
137 0//unsigned long flags
138 );
139 if (cycles_counter_main_fd<0) {
140 perror("Failed to open main cycles counter");
141 }
143 #endif
144 }