Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > DKU > DKU__Test_App
diff DKU_Fns.c @ 0:efca8e7ec576
initial add -- working version
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Tue, 24 Sep 2013 08:08:18 -0700 |
| parents | |
| children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/DKU_Fns.c Tue Sep 24 08:08:18 2013 -0700 1.3 @@ -0,0 +1,122 @@ 1.4 +/* 1.5 + * Copyright 2009 OpenSourceResearchInstitute.org 1.6 + * Licensed under GNU General Public License version 2 1.7 + * 1.8 + * Author: seanhalle@yahoo.com 1.9 + * 1.10 + */ 1.11 + 1.12 + 1.13 +#include <math.h> 1.14 +#include <string.h> 1.15 +#include "DKU__Test_App.h" 1.16 + 1.17 +/*Bare smoke test of DKU wrapper library functions. 1.18 + * Create one DKU instance, with a dummy kernel 1.19 + * Bare bones divider and undivider 1.20 + * simple root piece maker 1.21 + * dummy serial kernel 1.22 + */ 1.23 + 1.24 +int 1.25 +square( int x ) 1.26 + { return x*x; 1.27 + } 1.28 + 1.29 + 1.30 +DKUPiece * 1.31 +rootPieceMakerFn( void *params, DKUInstance *dkuInstance ) 1.32 + { DKUPiece *rootPiece; 1.33 + 1.34 + rootPiece = PRServ__DKU_make_empty_DKU_piece(); 1.35 + rootPiece->parent = NULL; 1.36 + rootPiece->payload = params; 1.37 + rootPiece->dkuInstance = dkuInstance; 1.38 + 1.39 + return rootPiece; 1.40 + } 1.41 + 1.42 +DKUPiece * 1.43 +make_root_dku_piece_for_test_inst( int32 *data, int32 size, 1.44 + DKUInstance *dkuInstance ) 1.45 + { DKUPiece *rootPiece; 1.46 + TestAppStruct *params; 1.47 + 1.48 + params = PR__malloc( sizeof(TestAppStruct) ); 1.49 + params->startIter = 0; 1.50 + params->endIter = size-1; 1.51 + params->data = data; 1.52 + params->size = size; 1.53 + rootPiece = (*(dkuInstance->rootPieceMaker))( params, dkuInstance ); 1.54 + return rootPiece; 1.55 + } 1.56 + 1.57 + 1.58 +void 1.59 +kernelFn( void *_params, SlaveVP *animVP ) 1.60 + { int32 i; 1.61 + DKUPiece *piece = (DKUPiece *)_params; 1.62 + TestAppStruct *params = (TestAppStruct *)piece->payload; 1.63 + int32 *data = params->data; 1.64 + 1.65 + DEBUG__printf(dbgAppFlow, "Kernel %d", params->startIter); 1.66 + 1.67 + for( i=params->startIter; i <= params->endIter; ++i ) 1.68 + { data[i] = square(i); 1.69 + } 1.70 + PRServ__DKU_end_kernel( piece, animVP ); 1.71 + } 1.72 + 1.73 + 1.74 +/*Serial kernel is called with bare app-defined struct, not DKUPiece 1.75 + */ 1.76 +void 1.77 +serialKernelFn( void *_params, SlaveVP *animVP ) 1.78 + { int32 i; 1.79 + TestAppStruct *params = (TestAppStruct *)_params; 1.80 + int32 *data = params->data; 1.81 + 1.82 + DEBUG__printf(dbgAppFlow, "SerialKernel %d", params->startIter); 1.83 + 1.84 + for( i=params->startIter; i < params->endIter; ++i ) 1.85 + { data[i] = square(i); 1.86 + } 1.87 + PRServ__DKU_end_serial_kernel( animVP ); 1.88 + } 1.89 + 1.90 +void 1.91 +dividerFn( DKUPiece *pieceToDivide ) 1.92 + { 1.93 + int32 idx, childIdx, numChildren, size, *data; 1.94 + DKUPiece *childPiece, **childrenArray; 1.95 + TestAppStruct *params; 1.96 + DEBUG__printf(dbgAppFlow, "divider %p", pieceToDivide) 1.97 + 1.98 + numChildren = pieceToDivide->numChildren; 1.99 + childrenArray = PR__malloc( numChildren * sizeof(DKUPiece *) ); 1.100 + size = ((TestAppStruct*)pieceToDivide->payload)->size; 1.101 + data = ((TestAppStruct*)pieceToDivide->payload)->data; 1.102 + int chunkSize = size/numChildren; //for portability, lang would choose this dynamically at run time 1.103 + //note: should do processing to catch too small a chunksize and deal w/it 1.104 + for( childIdx = 0; childIdx < numChildren; childIdx++ ) 1.105 + { params = PR__malloc(sizeof(TestAppStruct)); //these define work the task performs 1.106 + idx = childIdx * chunkSize; 1.107 + params->startIter = idx; 1.108 + params->endIter = idx + chunkSize -1; 1.109 + params->data = data; 1.110 + params->size = size; 1.111 + childPiece = PRServ__DKU_make_child_piece_from( pieceToDivide ); 1.112 + childPiece->payload = params; 1.113 + childrenArray[childIdx] = childPiece; 1.114 + } 1.115 + params->endIter = size -1; //catch truncation error from chunkSize calc 1.116 + 1.117 + pieceToDivide->children = childrenArray; 1.118 + } 1.119 + 1.120 +void undividerFn( DKUPiece *piece ) 1.121 + { 1.122 + //DEBUG__printf(dbgAppFlow, "Undivider %p", piece) 1.123 + //nothing to do -- request handler does counting of completions 1.124 + } 1.125 +
