# HG changeset patch # User Me # Date 1288146843 25200 # Node ID ec0629f70ee5f2ba5519a0707a7618980ef9b5db # Parent dd5387f362f696693f2f56f69b963e421209cb71 forgot to add some of the files diff -r dd5387f362f6 -r ec0629f70ee5 src/Application/CILK_Linux__Matrix_Mult Binary file src/Application/CILK_Linux__Matrix_Mult has changed diff -r dd5387f362f6 -r ec0629f70ee5 src/Application/CILK__Matrix_Mult/Divide_Pr.c --- a/src/Application/CILK__Matrix_Mult/Divide_Pr.c Tue Oct 26 19:32:46 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -/* - * Copyright 2009 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - - -#include "VPThread__Matrix_Mult.h" - -/*Divider creates one processor for every row-col pair. - * It hands them: - * the name of the result processor that they should send their results to, - * the left and right matrices, and the row and col they should multiply - * the length of the vector - * It first creates the result processor, then all the vector processors, - * then does a receive of a message from the result processor that gives - * the divider ownership of the result matrix. - * Finally, the divider returns the result matrix out of the VPThread system. - */ -void divideIntoVectors( void *_dividerParams, VirtProcr *animatingThd ) - { VirtProcr *resultsThd; - DividerParams *dividerParams; - ResultsParams *resultsParams; - VectorParams *vectParams; - Matrix *leftMatrix, *rightMatrix, *resultMatrix; - void *msg; - MatrixMultGlobals *globals; - -// printf("start divide\n"); fflush(stdin); - - dividerParams = (DividerParams *)_dividerParams; - - leftMatrix = dividerParams->leftMatrix; - rightMatrix = dividerParams->rightMatrix; - - resultsParams = malloc( sizeof(ResultsParams) ); - resultsParams->dividerThd = animatingThd; - resultsParams->numCols = rightMatrix->numCols; - resultsParams->numRows = leftMatrix->numRows; - - //=========== Set up global vars, including conds and mutexes =========== - globals = malloc( sizeof(MatrixMultGlobals) ); - VPThread__set_globals_to( globals ); - - globals->results_mutex = VPThread__make_mutex( animatingThd ); - globals->results_cond = VPThread__make_cond( globals->results_mutex, - animatingThd ); - - globals->vector_mutex = VPThread__make_mutex( animatingThd ); - globals->vector_cond = VPThread__make_cond( globals->vector_mutex, - animatingThd ); - - globals->start_mutex = VPThread__make_mutex( animatingThd ); - globals->start_cond = VPThread__make_cond( globals->start_mutex, - animatingThd ); - //======================================================================== - - //get results-comm lock before create results-thd, to ensure it can't - // signal that results are available before this thd is waiting on cond - VPThread__mutex_lock( globals->results_mutex, animatingThd ); - - //also get the start lock & use to ensure no vector threads send a - // signal before the results thread is waiting on vector cond - VPThread__mutex_lock( globals->start_mutex, animatingThd ); - - - VPThread__create_thread( &gatherResults, resultsParams, animatingThd ); - - //Now wait for results thd to signal that it has vector lock - VPThread__cond_wait( globals->start_cond, animatingThd ); - VPThread__mutex_unlock( globals->start_mutex, animatingThd );//done w/lock - - - //make the vector thds - int row, col; - for( row = 0; row < leftMatrix->numRows; row++ ) - { for( col = 0; col < rightMatrix->numCols; col++ ) - { - vectParams = malloc( sizeof(VectorParams) ); - vectParams->myCol = col; - vectParams->myRow = row; - vectParams->vectLength = leftMatrix->numCols; - vectParams->leftMatrix = leftMatrix; - vectParams->rightMatrix = rightMatrix; - - VPThread__create_thread( &calcVector, vectParams, animatingThd ); - } - //=================== DEBUG =================== - #ifdef PRINT_DEBUG_1 - printf("created thread: %d, %d\n", row, col); - #endif - //============================================== - } - - //Wait for results thread to say results are good - VPThread__cond_wait( globals->results_cond, animatingThd ); - - //The results of the all the work have to be linked-to from the data - // struc given to the seed procr -- this divide func is animated by - // that seed procr, so have to link results to the _dividerParams. - resultMatrix = malloc( sizeof(Matrix) ); - resultMatrix->numCols = rightMatrix->numCols; - resultMatrix->numRows = leftMatrix->numRows; - dividerParams->resultMatrix = resultMatrix; - resultMatrix->matrix = globals->results; - - //done with communication, release lock - VPThread__mutex_unlock( globals->results_mutex, animatingThd ); - - - VPThread__dissipate_thread( animatingThd ); //all Thds dissipate when done - //when all of the threads have dissipated, the "create seed and do - // work" call in the entry point function returns - } diff -r dd5387f362f6 -r ec0629f70ee5 src/Application/CILK__Matrix_Mult/Divide_Pr.cilk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Application/CILK__Matrix_Mult/Divide_Pr.cilk Tue Oct 26 19:34:03 2010 -0700 @@ -0,0 +1,72 @@ +/* + * Copyright 2009 OpenSourceStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + + +#include "CILK__Matrix_Mult.h" + +cilk float32 calcVector( void * ); + +/*Divider creates one processor for every row-col pair. + * It hands them: + * the name of the result processor that they should send their results to, + * the left and right matrices, and the row and col they should multiply + * the length of the vector + * It first creates the result processor, then all the vector processors, + * then does a receive of a message from the result processor that gives + * the divider ownership of the result matrix. + * Finally, the divider returns the result matrix out of the VPThread system. + */ + +cilk void divideIntoVectors( void *_dividerParams ) + { + DividerParams *dividerParams; + VectorParams *vectParams; + Matrix *leftMatrix, *rightMatrix, *resultMatrix; + int32 numCells, numCols, mrow, mcol; + float32 *resultMatrixArray; + + dividerParams = (DividerParams *)_dividerParams; + + leftMatrix = dividerParams->leftMatrix; + rightMatrix = dividerParams->rightMatrix; + + + numCols = rightMatrix->numCols; + + numCells = leftMatrix->numRows * rightMatrix->numCols; + resultMatrixArray = malloc( numCells * sizeof( float32 ) ); + + + //spawn vector calcs + for( mrow = 0; mrow < leftMatrix->numRows; mrow++ ) + { for( mcol = 0; mcol < rightMatrix->numCols; mcol++ ) + { + vectParams = malloc( sizeof(VectorParams) ); + vectParams->myCol = mcol; + vectParams->myRow = mrow; + vectParams->vectLength = leftMatrix->numCols; + vectParams->leftMatrix = leftMatrix; + vectParams->rightMatrix = rightMatrix; + + + resultMatrixArray[ mrow * numCols + mcol ] = spawn calcVector( vectParams ); + } + } + + sync; + + + //The results of the all the work have to be linked-to from the data + // struc given to the seed procr -- this divide func is animated by + // that seed procr, so have to link results to the _dividerParams. + resultMatrix = malloc( sizeof(Matrix) ); + resultMatrix->numCols = rightMatrix->numCols; + resultMatrix->numRows = leftMatrix->numRows; + dividerParams->resultMatrix = resultMatrix; + resultMatrix->matrix = resultMatrixArray; + } diff -r dd5387f362f6 -r ec0629f70ee5 src/Application/CILK__Matrix_Mult/EntryPoint.c --- a/src/Application/CILK__Matrix_Mult/EntryPoint.c Tue Oct 26 19:32:46 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright 2009 OpenSourceCodeStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -#include - -#include "VPThread__Matrix_Mult.h" - - - -/*Every VPThread system has an "entry point" function that creates the first - * processor, which starts the chain of creating more processors.. - * eventually all of the processors will dissipate themselves, and - * return. - * - *This entry-point function follows the same pattern as all entry-point - * functions do: - *1) it creates the params for the seed processor, from the - * parameters passed into the entry-point function - *2) it calls VPThread__create_seed_procr_and_do_work - *3) it gets the return value from the params struc, frees the params struc, - * and returns the value from the function - * - */ -Matrix * -multiplyTheseMatrices( Matrix *leftMatrix, Matrix *rightMatrix ) - { Matrix *resMatrix; - DividerParams *dividerParams; - - - dividerParams = malloc( sizeof( DividerParams ) ); - dividerParams->leftMatrix = leftMatrix; - dividerParams->rightMatrix = rightMatrix; - - - //create divider processor, start doing the work, and wait till done - //This function is the "border crossing" between normal code and VPThread - VPThread__create_seed_procr_and_do_work( ÷IntoVectors, dividerParams ); - - //get result matrix and return it - resMatrix = dividerParams->resultMatrix; - free( dividerParams ); - return resMatrix; - } diff -r dd5387f362f6 -r ec0629f70ee5 src/Application/CILK__Matrix_Mult/EntryPoint.cilk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Application/CILK__Matrix_Mult/EntryPoint.cilk Tue Oct 26 19:34:03 2010 -0700 @@ -0,0 +1,45 @@ +/* + * Copyright 2009 OpenSourceCodeStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#include "CILK__Matrix_Mult.h" + +cilk void divideIntoVectors( void * ); + +/*Every VPThread system has an "entry point" function that creates the first + * processor, which starts the chain of creating more processors.. + * eventually all of the processors will dissipate themselves, and + * return. + * + *This entry-point function follows the same pattern as all entry-point + * functions do: + *1) it creates the params for the seed processor, from the + * parameters passed into the entry-point function + *2) it calls VPThread__create_seed_procr_and_do_work + *3) it gets the return value from the params struc, frees the params struc, + * and returns the value from the function + * + */ +cilk +Matrix * +multiplyTheseMatrices( Matrix *leftMatrix, Matrix *rightMatrix ) + { Matrix *resMatrix; + DividerParams *dividerParams; + + + dividerParams = malloc( sizeof( DividerParams ) ); + dividerParams->leftMatrix = leftMatrix; + dividerParams->rightMatrix = rightMatrix; + + spawn divideIntoVectors( dividerParams ); + sync; + + //get result matrix and return it + resMatrix = dividerParams->resultMatrix; + free( dividerParams ); + return resMatrix; + } diff -r dd5387f362f6 -r ec0629f70ee5 src/Application/CILK__Matrix_Mult/Result_Pr.c --- a/src/Application/CILK__Matrix_Mult/Result_Pr.c Tue Oct 26 19:32:46 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -/* - * Copyright 2009 OpenSourceCodeStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -#include "VPThread__Matrix_Mult.h" - -/*The Result Processor gets a message from each of the vector processors, - * puts the result from the message in its location in the result- - * matrix, and increments the count of results. - * - *After the count reaches the point that all results have been received, it - * returns the result matrix and dissipates. - */ -void gatherResults( void *_params, VirtProcr *animatingPr ) - { VirtProcr *dividerPr; - ResultsParams *params; - int numRows, numCols, numCells, count=0; - float32 *resultMatrixArray; - void *msg; - VectorParams *aResult; - MatrixMultGlobals *globals =(MatrixMultGlobals *)VPThread__give_globals(); - - - //get vector-comm lock before loop, so that this thd keeps lock after - // one wait until it enters the next wait -- forces see-saw btwn - // waiters and signalers -- wait-signal-wait-signal-... - VPThread__mutex_lock( globals->vector_mutex, animatingPr ); - - //Tell divider that have the vector lock -- so it's sure won't miss any - // signals from the vector-threads it's about to create - //Don't need a signal variable -- this thd can't be created until - // divider thd already has the start lock - VPThread__mutex_lock( globals->start_mutex, animatingPr );//finish wait - VPThread__cond_signal( globals->start_cond, animatingPr ); - VPThread__mutex_unlock( globals->start_mutex, animatingPr );//finish wait - - //===================== DEBUG ====================== - #ifdef PRINT_DEBUG - printf("**Result Pr has the lock**\n" ); - fflush(stdin); - #endif - //==================================================== - - params = (ResultsParams *)_params; - dividerPr = params->dividerThd; - numCols = params->numCols; - numRows = params->numRows; - numCells = numRows * numCols; - - resultMatrixArray = malloc( numCells * sizeof( float32 ) ); - - - while( count < numCells ) - { - //receive a vector-result from a vector-thread - VPThread__cond_wait( globals->vector_cond, animatingPr ); - - aResult = globals->currVector; - *(resultMatrixArray + aResult->myRow * numCols + aResult->myCol) = - aResult->result; - count++; - //===================== DEBUG ====================== - #ifdef PRINT_DEBUG_1 - if( count - count/numRows * numRows == 0 ) - { printf("%d vector result: %f\n", count, aResult->result ); - fflush(stdin); - } - #endif - //==================================================== - - } - //all comms done, release lock - VPThread__mutex_unlock( globals->vector_mutex, animatingPr ); - - //Send result to divider (seed) thread - // note, divider thd had to hold the results-comm lock before creating - // this thread, to be sure no race - VPThread__mutex_lock( globals->results_mutex, animatingPr ); - globals->results = resultMatrixArray; - VPThread__cond_signal( globals->results_cond, animatingPr ); - VPThread__mutex_unlock( globals->results_mutex, animatingPr ); //releases - //divider thread from its wait, at point this executes - - VPThread__dissipate_thread( animatingPr ); //frees any data owned by procr - } diff -r dd5387f362f6 -r ec0629f70ee5 src/Application/CILK__Matrix_Mult/VMS_primitive_data_types.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Application/CILK__Matrix_Mult/VMS_primitive_data_types.h Tue Oct 26 19:34:03 2010 -0700 @@ -0,0 +1,53 @@ +/* + * Copyright 2009 OpenSourceStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + + */ + +#ifndef _BLIS_PRIMITIVE_DATA_TYPES_H +#define _BLIS_PRIMITIVE_DATA_TYPES_H + + +/*For portability, need primitive data types that have a well defined + * size, and well-defined layout into bytes + *To do this, provide BLIS standard aliases for all primitive data types + *These aliases must be used in all BLIS functions instead of the ANSI types + * + *These definitions will be replaced inside each specialization module + * according to the compiler used in that module and the hardware being + * specialized to. + */ +/* +#define int8 char +#define uint8 char +#define int16 short +#define uint16 unsigned short +#define int32 int +#define uint32 unsigned int +#define int64 long long +#define uint64 unsigned long long +#define float32 float +#define float64 double +*/ +typedef char bool8; +typedef char int8; +typedef char uint8; +typedef short int16; +typedef unsigned short uint16; +typedef int int32; +typedef unsigned int uint32; +typedef long long int64; +typedef unsigned long long uint64; +typedef float float32; +typedef double float64; +//typedef double double float128; +#define float128 double double + +#define TRUE 1 +#define FALSE 0 + +#endif /* _BLIS_PRIMITIVE_DATA_TYPES_H */ + diff -r dd5387f362f6 -r ec0629f70ee5 src/Application/CILK__Matrix_Mult/Vector_Pr.c --- a/src/Application/CILK__Matrix_Mult/Vector_Pr.c Tue Oct 26 19:32:46 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * Copyright 2009 OpenSourceCodeStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: SeanHalle@yahoo.com - * - */ - -#include "VPThread__Matrix_Mult.h" - -/*A Vector processor is created with an environment that holds two matrices, - * the row and col that it owns, and the name of a result gathering - * processor. - *It calculates its vector product then sends the result to the result - * processor, which puts it into the result matrix and returns that matrix - * when all is done. - */ - void -calcVector( void *data, VirtProcr *animatingPr ) - { - VectorParams *params; - VirtProcr *resultPr; - int myRow, myCol, vectLength, pos; - float32 *leftMatrixArray, *rightMatrixArray, result = 0.0; - Matrix *leftMatrix, *rightMatrix; - MatrixMultGlobals *globals =(MatrixMultGlobals *)VPThread__give_globals(); - - params = (VectorParams *)data; - myCol = params->myCol; - myRow = params->myRow; - vectLength = params->vectLength; - leftMatrix = params->leftMatrix; - rightMatrix = params->rightMatrix; - leftMatrixArray = leftMatrix->matrix; - rightMatrixArray = rightMatrix->matrix; - //===================== DEBUG ====================== - #ifdef PRINT_DEBUG_1 - if( myCol == 0 ) - printf("start vector: %d, %d\n", myRow, myCol ); fflush(stdin); - #endif - //==================================================== - - for( pos = 0; pos < vectLength; pos++ ) - { - result += *(leftMatrixArray + myRow * vectLength + pos) * - *(rightMatrixArray + pos * vectLength + myCol); - } - params->result = result; - - //Send result to results thread - VPThread__mutex_lock( globals->vector_mutex, animatingPr );//only get - //the lock when results thd is inside wait. - globals->currVector = params; - VPThread__cond_signal( globals->vector_cond, animatingPr ); - VPThread__mutex_unlock( globals->vector_mutex, animatingPr );//release - //wait-er -- cond_signal implemented such that wait-er gets lock, no other - - VPThread__dissipate_thread( animatingPr ); - } diff -r dd5387f362f6 -r ec0629f70ee5 src/Application/CILK__Matrix_Mult/Vector_Pr.cilk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Application/CILK__Matrix_Mult/Vector_Pr.cilk Tue Oct 26 19:34:03 2010 -0700 @@ -0,0 +1,48 @@ +/* + * Copyright 2009 OpenSourceCodeStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: SeanHalle@yahoo.com + * + */ + +#include "CILK__Matrix_Mult.h" + +/*A Vector processor is created with an environment that holds two matrices, + * the row and col that it owns, and the name of a result gathering + * processor. + *It calculates its vector product then sends the result to the result + * processor, which puts it into the result matrix and returns that matrix + * when all is done. + */ +cilk +float32 +calcVector( void *data ) + { + VectorParams *params; + int myRow, myCol, vectLength, pos; + float32 *leftMatrixArray, *rightMatrixArray, result = 0.0; + Matrix *leftMatrix, *rightMatrix; + + params = (VectorParams *)data; + myCol = params->myCol; + myRow = params->myRow; + vectLength = params->vectLength; + leftMatrix = params->leftMatrix; + rightMatrix = params->rightMatrix; + leftMatrixArray = leftMatrix->matrix; + rightMatrixArray = rightMatrix->matrix; + //===================== DEBUG ====================== + #ifdef PRINT_DEBUG + if( myCol == 0 ) + printf("start vector: %d, %d\n", myRow, myCol ); fflush(stdin); + #endif + //==================================================== + + for( pos = 0; pos < vectLength; pos++ ) + { + result += leftMatrixArray[ myRow * vectLength + pos ] * + rightMatrixArray[ pos * vectLength + myCol]; + } + return result; + } diff -r dd5387f362f6 -r ec0629f70ee5 src/Application/CILK__Matrix_Mult/matmul.cilk --- a/src/Application/CILK__Matrix_Mult/matmul.cilk Tue Oct 26 19:32:46 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,198 +0,0 @@ -/* - * Rectangular matrix multiplication. - * - * See the paper ``Cache-Oblivious Algorithms'', by - * Matteo Frigo, Charles E. Leiserson, Harald Prokop, and - * Sridhar Ramachandran, FOCS 1999, for an explanation of - * why this algorithm is good for caches. - * - * Author: Matteo Frigo - */ -static const char *ident __attribute__((__unused__)) - = "$HeadURL: https://bradley.csail.mit.edu/svn/repos/cilk/5.4.3/examples/matmul.cilk $ $LastChangedBy: sukhaj $ $Rev: 517 $ $Date: 2003-10-27 10:05:37 -0500 (Mon, 27 Oct 2003) $"; - -/* - * Copyright (c) 2003 Massachusetts Institute of Technology - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include - -#define REAL float - -extern int Cilk_rand(void); - -void zero(REAL *A, int n) -{ - int i, j; - - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) { - A[i * n + j] = 0.0; - } - } -} - -void init(REAL *A, int n) -{ - int i, j; - - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) { - A[i * n + j] = (double)Cilk_rand(); - } - } -} - -double maxerror(REAL *A, REAL *B, int n) -{ - int i, j; - double error = 0.0; - - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) { - double diff = (A[i * n + j] - B[i * n + j]) / A[i * n + j]; - if (diff < 0) - diff = -diff; - if (diff > error) - error = diff; - } - } - return error; -} - -void iter_matmul(REAL *A, REAL *B, REAL *C, int n) -{ - int i, j, k; - - for (i = 0; i < n; i++) - for (k = 0; k < n; k++) { - REAL c = 0.0; - for (j = 0; j < n; j++) - c += A[i * n + j] * B[j * n + k]; - C[i * n + k] = c; - } -} - -/* - * A \in M(m, n) - * B \in M(n, p) - * C \in M(m, p) - */ -cilk void rec_matmul(REAL *A, REAL *B, REAL *C, int m, int n, int p, int ld, - int add) -{ - if ((m + n + p) <= 64) { - int i, j, k; - /* base case */ - if (add) { - for (i = 0; i < m; i++) - for (k = 0; k < p; k++) { - REAL c = 0.0; - for (j = 0; j < n; j++) - c += A[i * ld + j] * B[j * ld + k]; - C[i * ld + k] += c; - } - } else { - for (i = 0; i < m; i++) - for (k = 0; k < p; k++) { - REAL c = 0.0; - for (j = 0; j < n; j++) - c += A[i * ld + j] * B[j * ld + k]; - C[i * ld + k] = c; - } - } - } else if (m >= n && n >= p) { - int m1 = m >> 1; - spawn rec_matmul(A, B, C, m1, n, p, ld, add); - spawn rec_matmul(A + m1 * ld, B, C + m1 * ld, m - m1, - n, p, ld, add); - } else if (n >= m && n >= p) { - int n1 = n >> 1; - spawn rec_matmul(A, B, C, m, n1, p, ld, add); - sync; - spawn rec_matmul(A + n1, B + n1 * ld, C, m, n - n1, p, ld, 1); - } else { - int p1 = p >> 1; - spawn rec_matmul(A, B, C, m, n, p1, ld, add); - spawn rec_matmul(A, B + p1, C + p1, m, n, p - p1, ld, add); - } -} - -cilk int main(int argc, char *argv[]) -{ - int n; - REAL *A, *B, *C1, *C2; - double err; - Cilk_time tm_begin, tm_elapsed; - Cilk_time wk_begin, wk_elapsed; - Cilk_time cp_begin, cp_elapsed; - - if (argc != 2) { - fprintf(stderr, "Usage: matmul [] \n"); - Cilk_exit(1); - } - n = atoi(argv[1]); - - A = malloc(n * n * sizeof(REAL)); - B = malloc(n * n * sizeof(REAL)); - C1 = malloc(n * n * sizeof(REAL)); - C2 = malloc(n * n * sizeof(REAL)); - - init(A, n); - init(B, n); - zero(C1, n); - zero(C2, n); - - iter_matmul(A, B, C1, n); - - /* Timing. "Start" timers */ - sync; - cp_begin = Cilk_user_critical_path; - wk_begin = Cilk_user_work; - tm_begin = Cilk_get_wall_time(); - - spawn rec_matmul(A, B, C2, n, n, n, n, 0); - sync; - - /* Timing. "Stop" timers */ - tm_elapsed = Cilk_get_wall_time() - tm_begin; - wk_elapsed = Cilk_user_work - wk_begin; - cp_elapsed = Cilk_user_critical_path - cp_begin; - - err = maxerror(C1, C2, n); - - printf("\nCilk Example: matmul\n"); - printf(" running on %d processor%s\n\n", - Cilk_active_size, Cilk_active_size > 1 ? "s" : ""); - printf("Max error = %g\n", err); - printf("Options: size = %d\n", n); - printf("Running time = %4f s\n", Cilk_wall_time_to_sec(tm_elapsed)); - printf("Work = %4f s\n", Cilk_time_to_sec(wk_elapsed)); - printf("Critical path = %4f s\n", Cilk_time_to_sec(cp_elapsed)); - printf("``MFLOPS'' = %4f\n\n", - 2.0 * n * n * n / (1.0e6 * Cilk_wall_time_to_sec(tm_elapsed))); - - free(C2); - free(C1); - free(B); - free(A); - return 0; -} diff -r dd5387f362f6 -r ec0629f70ee5 src/Application/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Application/Makefile Tue Oct 26 19:34:03 2010 -0700 @@ -0,0 +1,80 @@ + + +CILK_SOURCE = \ + CILK__Matrix_Mult/EntryPoint.cilk \ + CILK__Matrix_Mult/Divide_Pr.cilk \ + CILK__Matrix_Mult/Vector_Pr.cilk \ + main.cilk + +C_SOURCE = \ + matrix_mult.c \ + ParamHelper/ParamBag.c\ + ParamHelper/ReadParamsFromFile.c + +C_OBJS = $(C_SOURCE:.c=.o) + +CILK_OBJS = $(CILK_SOURCE:.cilk=.o) + +OBJECTS = $(C_SOURCE) $(CILK_SOURCE) + +#Make has the built-in variable "$<" which is the source file +# and "$@" which is the target for that source +$(C_OBJS): $(C_SOURCE) + gcc -c $< -o $@ + +$(CILK_OBJS): $(CILK_SOURCE) + gcc -c $< -o $@ + +all: $(OBJECTS) + cilkc $(OBJECTS) -o CILK_Linux__Matrix_Mult; \ + cp CILK_Linux__Matrix_Mult ~/D/2__INRIA_OMP/1__Development/2__runs_and_data/executables + + + +#================================================================ +#Other stuff tried/played_with/copied +#Example called "specifying alternate directories" +# puts all object files in one directory +#CFLAGS := +#OBJDIR := . + +#$(OBJDIR)/%.o: %.c +# $(CC) $(CFLAGS) -c $(input) -o $(output) + +#Believe that make fills in "inputs".. and because have the +# sub-dir in the target, it puts that sub-dir into "inputs" var +# but apparently because the source is in objects dir, it doesn't +# include the sub-dir in the "output" var +#$(OBJDIR)/CILK_Matrix_Mult: $(OBJDIR)/*.o +# cilkc $(input) -o $(output) + +#%.o: %.cilk + + +#=============================================================== +#May be odd usage.. my first makefile.. idea is to tell make +# that to get a give .o file, to run cilkc w/"-c" option, which +# causes cilkc to generate a ".o" file +#%.o: %.cilk +# cilkc -c $< -o $@ + + +#================================================================ +# playing with below.. + +#7C9A-RV6P-3XE2-JV99-426K-2K + +#rule for inferring that the .cilk file is the source for .o file +# and how to create the .o from the .cilk +#%.o : %.cilk +# cilkc -c $(.SOURCE) + +#CILK_Linux__Matrix_Mult: main.o CILK__Matrix_Mult/foo.o #ParamHelper/foo2.o + +#foo.o: $(SUBDIR_SOURCES) +# gcc -shared $(inputs) -o $(output) + +#%.o: %.cilk +# cilkc -c $(input) -o $(output) + + diff -r dd5387f362f6 -r ec0629f70ee5 src/Application/main.c --- a/src/Application/main.c Tue Oct 26 19:32:46 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - * Copyright Oct 24, 2009 OpenSourceCodeStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * author seanhalle@yahoo.com - */ - -#include -#include - -#include "Matrix_Mult.h" -#include "VPThread__Matrix_Mult/VPThread__Matrix_Mult.h" - -/** - *Matrix multiply program written using VMS_HW piggy-back language - * - */ -int main( int argc, char **argv ) - { Matrix *leftMatrix, *rightMatrix, *resultMatrix; - ParamBag *paramBag; - - paramBag = makeParamBag(); - readParamFileIntoBag( argv[1], paramBag ); - initialize_Input_Matrices_Via( &leftMatrix, &rightMatrix, paramBag ); - - resultMatrix = multiplyTheseMatrices( leftMatrix, rightMatrix ); - - printf("\nresult matrix: \n"); - -// printMatrix( resultMatrix ); - -// VPThread__print_stats(); - - exit(0); //cleans up - } diff -r dd5387f362f6 -r ec0629f70ee5 src/Application/main.cilk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Application/main.cilk Tue Oct 26 19:34:03 2010 -0700 @@ -0,0 +1,41 @@ +/* + * Copyright Oct 24, 2009 OpenSourceCodeStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * author seanhalle@yahoo.com + */ + +#include +#include + +#include "Matrix_Mult.h" +#include "CILK__Matrix_Mult/CILK__Matrix_Mult.h" + +cilk Matrix * +multiplyTheseMatrices( Matrix *leftMatrix, Matrix *rightMatrix ); + +/** + *Matrix multiply program written using VMS_HW piggy-back language + * + */ +cilk +int main( int argc, char **argv ) + { Matrix *leftMatrix, *rightMatrix, *resultMatrix; + ParamBag *paramBag; + + + paramBag = makeParamBag(); + readParamFileIntoBag( argv[1], paramBag ); + initialize_Input_Matrices_Via( &leftMatrix, &rightMatrix, paramBag ); + + resultMatrix = spawn multiplyTheseMatrices( leftMatrix, rightMatrix ); + sync; + + printf("\nresult matrix: \n"); + +// printMatrix( resultMatrix ); + +// VPThread__print_stats(); + + exit(0); //cleans up + }