annotate main.c @ 0:c4b1849c05ef

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