int main(int argc, const char * argv[]) { ocrConfig_t ocrConfig; ocrParseArgs(argc, argv, &ocrConfig); ocrInit(&ocrConfig); ocrGuid_t terminateEdtGuid; ocrGuid_t terminateEdtTemplateGuid; ocrEdtTemplateCreate(&terminateEdtTemplateGuid, terminateEdt, 0 /*paramc*/, 1 /*depc*/); ocrEdtCreate(&terminateEdtGuid, terminateEdtTemplateGuid, EDT_PARAM_DEF, /*paramv=*/NULL, EDT_PARAM_DEF, /*depv=*/NULL, /*properties=*/0, NULL_GUID, /*outEvent=*/NULL); ocrGuid_t outputEventGuid; ocrGuid_t rootEdtGuid; ocrGuid_t rootEdtTemplateGuid; ocrEdtTemplateCreate(&rootEdtTemplateGuid, rootEdt, 0 /*paramc*/, 0 /*depc*/); ocrEdtCreate(&rootEdtGuid, rootEdtTemplateGuid, EDT_PARAM_DEF, /*paramv=*/NULL, EDT_PARAM_DEF, /*depv=*/NULL, /*properties=*/EDT_PROP_FINISH, NULL_GUID, /*outEvent=*/&outputEventGuid); // When output-event will be satisfied, the whole task sub-tree // spawned by rootEdt will be done, and shutdownEdt is called. ocrAddDependence(outputEventGuid, terminateEdtGuid, 0, DB_MODE_RO); ocrFinalize(); return 0; }
ocrGuid_t mainEdt(){ /* mainEdt is executed first Creates the datablocks creates realmain as a FINISH EDT creates wrap up to depend on realmain launches realmain (wrapup waits until realmain is done) */ u64 i; u64 *dummy; ocrGuid_t realMain, GSsharedBlock, userSharedBlock, realMainTemplate, output, wrapup, wrapupTemplate; PRINTF("Preconditioned driver\n"); PRINTF("Number of timesteps is %d \n", T); PRINTF("Number of workers is %d \n", N); PRINTF("Rows per worker %d \n", M); ocrEdtTemplateCreate(&wrapupTemplate, wrapupEdt, 0, 1); ocrEdtTemplateCreate(&realMainTemplate, realMainEdt, 0, 2); ocrEdtCreate(&realMain, realMainTemplate, EDT_PARAM_DEF, NULL, EDT_PARAM_DEF, NULL, EDT_PROP_FINISH, NULL_GUID, &output); ocrDbCreate(&GSsharedBlock, (void **) &dummy, sizeof(GSsharedBlock_t), 0, NULL_GUID, NO_ALLOC); ocrDbCreate(&userSharedBlock, (void **) &dummy, sizeof(userSharedBlock_t), 0, NULL_GUID, NO_ALLOC); ocrEdtCreate(&wrapup, wrapupTemplate, EDT_PARAM_DEF, NULL, EDT_PARAM_DEF, NULL, EDT_PROP_FINISH, NULL_GUID, NULL_GUID); ocrAddDependence(output, wrapup, 0, DB_MODE_RW); ocrAddDependence(userSharedBlock, realMain, 0, DB_MODE_RW); ocrAddDependence(GSsharedBlock, realMain, 1, DB_MODE_RW); return NULL_GUID; }
ocrGuid_t realMainEdt(u32 paramc, u64 *paramv, u32 depc, ocrEdtDep_t depv[]){ /* paramv[0]: number of workers for GSi to create depv 0: userSharedBlock 1: GSsharedBlock realMain launches the GS initialization */ u64 i, mynode; ocrGuid_t once; userSharedBlock_t * uSB = depv[0].ptr; GSsharedBlock_t * SB = depv[1].ptr; SB->numnodes = N; //setting the number of "ranks" REQUIRED ocrEdtTemplateCreate(&(uSB->cgTemplate), cgTask, 3, 4); SB->userBlock = depv[0].guid; //passed through GSiEDT to computeInitEdt ocrGuid_t gsBlock, GSi, sticky, dummy; ocrEdtTemplateCreate(&(SB->GSiTemplate), GSiEdt, 3, 2); //needed both to launch GSiEDT and inside for cloning REQUIRED ocrDbCreate(&(gsBlock), (void**) &dummy, sizeof(gsBlock_t), 0, NULL_GUID, NO_ALLOC); //needed for GSiEDT REQUIRED //create and luanch GSiEdt u64 GSparamvout[3] = {0, NULL_GUID, NULL_GUID}; //REQUIRED ocrEdtCreate(&GSi, SB->GSiTemplate, EDT_PARAM_DEF, GSparamvout, EDT_PARAM_DEF, NULL_GUID, EDT_PROP_NONE, NULL_GUID, NULL_GUID); //REQUIRED ocrDbRelease(depv[1].guid); ocrAddDependence(depv[1].guid, GSi, 0, DB_MODE_RW); //REQUIRED ocrAddDependence(gsBlock, GSi, 1, DB_MODE_RW); //REQUIRED return NULL_GUID; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { u64 affinityCount; ocrAffinityCount(AFFINITY_PD, &affinityCount); ocrGuid_t dbAffGuid; ocrGuid_t * dbAffPtr; ocrDbCreate(&dbAffGuid, (void **)&dbAffPtr, sizeof(ocrGuid_t) * affinityCount, DB_PROP_SINGLE_ASSIGNMENT, NULL_HINT, NO_ALLOC); ocrAffinityGet(AFFINITY_PD, &affinityCount, dbAffPtr); ASSERT(affinityCount >= 1); // create local edt that depends on the remote edt, the db is automatically cloned ocrGuid_t remoteEdtTemplateGuid; ocrEdtTemplateCreate(&remoteEdtTemplateGuid, remoteEdt, 0, 1); ocrGuid_t eventsGuid[COUNT_EDT]; ocrGuid_t dbsGuid[COUNT_EDT]; u64 i = 0; while(i < COUNT_EDT) { ocrEventCreate(&eventsGuid[i],OCR_EVENT_ONCE_T, EVT_PROP_NONE); ocrGuid_t * dbPtr; ocrDbCreate(&dbsGuid[i], (void **)&dbPtr, sizeof(ocrGuid_t)*2, DB_PROP_SINGLE_ASSIGNMENT, NULL_HINT, NO_ALLOC); dbPtr[0] = eventsGuid[i]; dbPtr[1] = dbAffPtr[i%affinityCount]; ocrDbRelease(dbsGuid[i]); i++; } ocrDbRelease(dbAffGuid); // Setup shutdown EDT ocrGuid_t shutdownEdtTemplateGuid; ocrEdtTemplateCreate(&shutdownEdtTemplateGuid, shutdownEdt, 0, COUNT_EDT); ocrHint_t edtHint; ocrHintInit( &edtHint, OCR_HINT_EDT_T ); ocrGuid_t shutdownEdtGuid; ocrEdtCreate(&shutdownEdtGuid, shutdownEdtTemplateGuid, 0, NULL, EDT_PARAM_DEF, eventsGuid, EDT_PROP_NONE, NULL_HINT, NULL); // Spawn 'COUNT_EDT' EDTs, each satisfying its event i = 0; while(i < COUNT_EDT) { ocrSetHintValue( & edtHint, OCR_HINT_EDT_AFFINITY, ocrAffinityToHintValue( dbAffPtr[i%affinityCount]) ); // Create EDTs ocrGuid_t edtGuid; ocrEdtCreate(&edtGuid, remoteEdtTemplateGuid, 0, NULL, EDT_PARAM_DEF, &dbsGuid[i], EDT_PROP_NONE, &edtHint, NULL); i++; } return NULL_GUID; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { u64 arraySize = 100; //Create argument vector to hold array size u64 nparamv[1]; nparamv[0] = arraySize; u64 * dataArray; ocrGuid_t dataGuid; //Create datablock to hold a block of 'array size' u64 elements ocrDbCreate(&dataGuid,(void **) &dataArray, sizeof(u64)*arraySize, /*flags=*/0, /*loc=*/NULL_GUID, NO_ALLOC); ocrGuid_t stepAEdtTemplateGuid; ocrEdtTemplateCreate(&stepAEdtTemplateGuid, stepA_edt, 1 /*paramc*/, 1 /*depc*/); // Create the EDT not specifying the dependence vector at creation ocrGuid_t stepAEdtGuid; ocrEdtCreate(&stepAEdtGuid, stepAEdtTemplateGuid, EDT_PARAM_DEF, nparamv, 1, NULL, /*prop=*/EDT_PROP_NONE, NULL_GUID, NULL); ocrGuid_t triggerEventGuid; //TODO Setup event used to trigger stepA //END-TODO //TODO Setup dependence between event and stepA's EDTs slot 0 //END-TODO //TODO Satisfy the event with the datablock //END-TODO return NULL_GUID; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { // Current thread is '0' and goes on with user code. ocrGuid_t e0; ocrEventCreate(&e0, OCR_EVENT_ONCE_T, EVT_PROP_TAKES_ARG); // Creates the EDTa ocrGuid_t edtGuid; ocrGuid_t taskForEdtTemplateGuid; ocrEdtTemplateCreate(&taskForEdtTemplateGuid, taskForEdt, 0 /*paramc*/, 2/*depc*/); ocrEdtCreate(&edtGuid, taskForEdtTemplateGuid, EDT_PARAM_DEF, /*paramv=*/NULL, EDT_PARAM_DEF, /*depv=*/NULL, /*properties=*/0, NULL_HINT, /*outEvent=*/NULL); // Register a dependence between an event and an edt ocrAddDependence(e0, edtGuid, 0, DB_MODE_CONST); ocrAddDependence(e0, edtGuid, 1, DB_MODE_CONST); int *k; ocrGuid_t dbGuid; ocrDbCreate(&dbGuid,(void **) &k, sizeof(int), /*flags=*/DB_PROP_NONE, /*location=*/NULL_HINT, NO_ALLOC); *k = 42; // Satisfy event's chain head ocrEventSatisfy(e0, dbGuid); return NULL_GUID; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { ocrGuid_t tplGuid; ocrEdtTemplateCreate(&tplGuid, otherEdt, 0 /*paramc*/, 2 /*depc*/); ocrGuid_t edtGuid; ocrGuid_t ndepv[2]; ndepv[0] = UNINITIALIZED_GUID; ndepv[1] = UNINITIALIZED_GUID; ocrEdtCreate(&edtGuid, tplGuid, 0, NULL, 2, ndepv, EDT_PROP_NONE, NULL_HINT, NULL); ocrEdtTemplateDestroy(tplGuid); ocrGuid_t db1Guid; u64 * db1Ptr; ocrDbCreate(&db1Guid, (void**) &db1Ptr, sizeof(u64), DB_PROP_NONE, NULL_HINT, NO_ALLOC); db1Ptr[0] = 1; ocrDbRelease(db1Guid); ocrGuid_t db2Guid; u64 * db2Ptr; ocrDbCreate(&db2Guid, (void**) &db2Ptr, sizeof(u64), DB_PROP_NONE, NULL_HINT, NO_ALLOC); db2Ptr[0] = 2; ocrDbRelease(db2Guid); ocrAddDependence(db1Guid, edtGuid, 0, DB_MODE_RO); ocrAddDependence(db2Guid, edtGuid, 1, DB_MODE_RO); return NULL_GUID; }
// paramv[0]: event to satisfy when kernel is done // depv[0]: setupEdt completed (may carry a DB) ocrGuid_t kernelEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { // PRINTF("kernelEdt\n"); ocrGuid_t kernelEdtDoneEvt; kernelEdtDoneEvt.guid = paramv[0]; ocrGuid_t setupDb = depv[0].guid; domainSetup_t * setupDbPtr = depv[0].ptr; // The sub kernel done event ocrGuid_t subKernelDoneEvt; ocrEventCreate(&subKernelDoneEvt, OCR_EVENT_ONCE_T, true); // This EDT done event ocrGuid_t selfDoneEvt; ocrEventCreate(&selfDoneEvt, OCR_EVENT_ONCE_T, true); // Combine those in a combine EDT that satisfies kernelEdtDoneEvt //TODO same issue of allocating tpl every iteration ocrGuid_t curAffGuid; ocrAffinityGetCurrent(&curAffGuid); ocrGuid_t combEdtTplGuid; ocrEdtTemplateCreate(&combEdtTplGuid, combineKernelEdt, 1, 2); ocrGuid_t combineEdtGuid; combine(&combineEdtGuid, combEdtTplGuid, curAffGuid, selfDoneEvt, subKernelDoneEvt, kernelEdtDoneEvt); ocrEdtTemplateDestroy(combEdtTplGuid); timestamp_t timer; domainKernel(subKernelDoneEvt, setupDbPtr, &timer); // Satisfy self event with the timer information ocrEventSatisfy(selfDoneEvt, setupDb); return NULL_GUID; }
void test () { // Current thread is '0' and goes on with user code. ocrGuid_t eventGuid; ocrEventCreate(&eventGuid, OCR_EVENT_STICKY_T, true); // Creates the EDT ocrGuid_t edtGuid; ocrGuid_t taskForEdtTemplateGuid; ocrEdtTemplateCreate(&taskForEdtTemplateGuid, taskForEdt, 0 /*paramc*/, 1 /*depc*/); ocrEdtCreate(&edtGuid, taskForEdtTemplateGuid, EDT_PARAM_DEF, /*paramv=*/NULL, EDT_PARAM_DEF, /*depv=*/NULL, 0, NULL_GUID, NULL); // Register a dependence between an event and an edt ocrAddDependence(eventGuid, edtGuid, 0, DB_MODE_RO); int *k; ocrGuid_t db_guid; ocrDbCreate(&db_guid,(void **) &k, sizeof(int), /*flags=*/FLAGS, /*location=*/NULL_GUID, NO_ALLOC); *k = 42; ocrEventSatisfy(eventGuid, db_guid); }
// Create an event at the current affinity and writes // the GUID into the domainSetup data-structure. void domainSetup(ocrGuid_t userSetupDoneEvt, domainSetup_t * dsetup) { // This is for the domain kernel to callback and stop the timer ocrGuid_t stopTimerEvt; ocrEventCreate(&stopTimerEvt, OCR_EVENT_ONCE_T, true); // Create an EDT at a remote affinity to: // - Create a remote latch event and initialize it // - Hook that event to the local event declared above // - write back the guid of the remote latch event into the setup DB // - userSetupDoneEvt: to be satisfied when setup is done // - stopTimerEvt: to be satisfied when domain kernel is done dsetup->userSetupDoneEvt = userSetupDoneEvt; dsetup->stopTimerEvt = stopTimerEvt; u64 affinityCount; ocrAffinityCount(AFFINITY_PD, &affinityCount); ocrGuid_t remoteAffGuid; ocrAffinityGetAt(AFFINITY_PD, affinityCount-1, &remoteAffGuid); ocrHint_t edtHint; ocrHintInit(&edtHint, OCR_HINT_EDT_T); ocrSetHintValue(&edtHint, OCR_HINT_EDT_AFFINITY, ocrAffinityToHintValue(remoteAffGuid)); ocrGuid_t edtTemplGuid; ocrEdtTemplateCreate(&edtTemplGuid, remoteSetupUserEdt, 0, 1); ocrGuid_t edtGuid; ocrEdtCreate(&edtGuid, edtTemplGuid, 0, NULL, 1, NULL, EDT_PROP_NONE, &edtHint, NULL); // EW addresses the race that the current caller owns the DB and we're // trying to start the remote setup EDT concurrently. Since we do not have // the caller event we can't setup a proper dependence and rely on EW instead. ocrAddDependence(dsetup->self, edtGuid, 0, DB_MODE_EW); ocrEdtTemplateDestroy(edtTemplGuid); }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { u64 affinityCount; ocrAffinityCount(AFFINITY_PD, &affinityCount); ocrGuid_t dbAffGuid; ocrGuid_t * dbAffPtr; ocrDbCreate(&dbAffGuid, (void **)&dbAffPtr, sizeof(ocrGuid_t) * affinityCount, DB_PROP_SINGLE_ASSIGNMENT, NULL_HINT, NO_ALLOC); ocrAffinityGet(AFFINITY_PD, &affinityCount, dbAffPtr); ASSERT(affinityCount >= 1); ocrGuid_t affinityGuid = dbAffPtr[affinityCount-1]; ocrDbRelease(dbAffGuid); // Finish EDT potentially remote, but spawning all children on the same node ocrGuid_t finishEdtTemplateGuid; ocrEdtTemplateCreate(&finishEdtTemplateGuid, finishEdt, 0, 0); ocrHint_t edtHint; ocrHintInit( &edtHint, OCR_HINT_EDT_T ); ocrSetHintValue( & edtHint, OCR_HINT_EDT_AFFINITY, ocrAffinityToHintValue( affinityGuid) ); PRINTF("mainEdt: spawning remote finish-EDT\n"); ocrGuid_t edtGuid; ocrEdtCreate(&edtGuid, finishEdtTemplateGuid, 0, NULL, EDT_PARAM_DEF, 0, EDT_PROP_NONE, &edtHint, NULL); return NULL_GUID; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { // Create a DB void * dbPtr; ocrGuid_t dbGuid; u64 nbElem = NB_ELEM_DB; ocrDbCreate(&dbGuid, &dbPtr, sizeof(TYPE_ELEM_DB) * NB_ELEM_DB, 0, NULL_HINT, NO_ALLOC); int v = 1; int i = 0; int * data = (int *) dbPtr; while (i < nbElem) { data[i] = v++; i++; } ocrDbRelease(dbGuid); PRINTF("[local] mainEdt: local DB guid is "GUIDF", dbPtr=%p\n", GUIDA(dbGuid), dbPtr); // create local edt that depends on the remote edt, the db is automatically cloned ocrGuid_t readerEdtTemplateGuid; ocrEdtTemplateCreate(&readerEdtTemplateGuid, readerEdt, 0, 3); ocrGuid_t dbGuids [3] = {dbGuid, dbGuid, dbGuid}; ocrGuid_t readerEdtGuid; ocrEdtCreate(&readerEdtGuid, readerEdtTemplateGuid, 0, NULL, 3, dbGuids, EDT_PROP_NONE, NULL_HINT, NULL); return NULL_GUID; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { // Creates a data block int *k; ocrGuid_t dbGuid; ocrDbCreate(&dbGuid,(void **) &k, sizeof(int), /*flags=*/0, /*location=*/NULL_GUID, NO_ALLOC); *k = 42; ocrGuid_t eventGuid; ocrEventCreate(&eventGuid, OCR_EVENT_STICKY_T, true); // Creates the EDT ocrGuid_t edtGuid; ocrGuid_t taskForEdtTemplateGuid; ocrEdtTemplateCreate(&taskForEdtTemplateGuid, taskForEdt, 0 /*paramc*/, 1 /*depc*/); ocrEdtCreate(&edtGuid, taskForEdtTemplateGuid, EDT_PARAM_DEF, /*paramv=*/NULL, EDT_PARAM_DEF, /*depv=*/NULL, /*properties=*/0, NULL_GUID, /*outEvent=*/NULL); ocrAddDependence(eventGuid, edtGuid, 0, DB_MODE_RO); // Register a dependence between a db and an event // (equivalent to directly satisfying the DB) ocrAddDependence(dbGuid, eventGuid, 0, DB_MODE_RO); // No need to satisfy as addDependence is equivalent to a satisfy // when the source is a datablock return NULL_GUID; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { // Current thread is '0' and goes on with user code. ocrGuid_t ndepv[1]; ocrGuid_t eventGuid; ocrEventCreate(&eventGuid, OCR_EVENT_STICKY_T, true); ndepv[0] = eventGuid; // Creates the EDT u32 nparamc = 1; u64 nparamv = 32; // 'ndepv' stores dependencies, so no need to call // ocrAddDependence later on to register events. ocrGuid_t edtGuid; ocrGuid_t taskForEdtTemplateGuid; ocrEdtTemplateCreate(&taskForEdtTemplateGuid, taskForEdt, nparamc, 1 /*depc*/); ocrEdtCreate(&edtGuid, taskForEdtTemplateGuid, EDT_PARAM_DEF, &nparamv, EDT_PARAM_DEF, /*depv=*/ndepv, /*properties=*/0, NULL_HINT, /*outEvent=*/NULL); int *k; ocrGuid_t dbGuid; ocrDbCreate(&dbGuid,(void **) &k, sizeof(int), /*flags=*/DB_PROP_NONE, /*location=*/NULL_HINT, NO_ALLOC); *k = 42; ocrEventSatisfy(eventGuid, dbGuid); return NULL_GUID; }
// This is the "key" EDT that is responsible for spawning all the workers ocrGuid_t keyEdt ( u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { ocrGuid_t templateGuid; ocrEdtTemplateCreate(&templateGuid, workerEdt, 0, 0); ocrGuid_t edtGuid; ocrEdtCreate(&edtGuid, templateGuid, 0, NULL, 0, NULL, EDT_PROP_FINISH, NULL_HINT, NULL); return NULL_GUID; }
ocrGuid_t mainEdt ( u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { u64 size = -1; u64 offset = -1; u32 i = 0; u64 argc; void *programArg = depv[0].ptr; argc = getArgc(programArg); if ( argc != 4 ) { PRINTF("Usage: ./basicIO offset size fileName \n"); ocrShutdown(); return 1; } offset = atoi(getArgv(programArg, 1)); size = atoi(getArgv(programArg, 2)); u64 nparamv[2]; nparamv[0] = offset; nparamv[1] = size; FILE *in; in = fopen(getArgv(programArg, 3), "r"); if( !in ) { PRINTF("Cannot find file: %s\n", getArgv(programArg, 3)); ocrShutdown(); return NULL_GUID; } ocrGuid_t dataGuid; // Data can be passed as parameter also , there was no // necessary need of creating data block in this example. // Its has been created for demo purpose //Create datablock to hold a block of 'size' elements u64 *inputarr; ocrDbCreate(&dataGuid, (void**)&inputarr, sizeof(u64)*size,0,NULL_GUID, NO_ALLOC); #ifndef TG_ARCH while(fscanf(in,"%llu\n",&inputarr[i++])!=EOF); #else fread(inputarr, sizeof(u64),size , in); #endif fclose(in); ocrGuid_t addEdtTemplateGuid; ocrEdtTemplateCreate(&addEdtTemplateGuid, add_edt, 2 /*paramc*/, 1 /*depc*/); ocrGuid_t add_edt_guid; // Create the EDT not specifying the dependence vector at creation ocrEdtCreate(&add_edt_guid, addEdtTemplateGuid, EDT_PARAM_DEF, nparamv,1,NULL ,EDT_PROP_FINISH , NULL_GUID, NULL); ocrGuid_t triggerEventGuid; ocrEventCreate(&triggerEventGuid, OCR_EVENT_STICKY_T, true); ocrAddDependence(triggerEventGuid, add_edt_guid, 0, DB_MODE_EW); ocrEventSatisfy(triggerEventGuid, dataGuid); return NULL_GUID; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { ocrGuid_t terminateEdtGuid; ocrGuid_t terminateEdtTemplateGuid; ocrEdtTemplateCreate(&terminateEdtTemplateGuid, terminateEdt, EDT_PARAM_UNK /*paramc*/, 0 /*depc*/); u8 res = ocrEdtCreate(&terminateEdtGuid, terminateEdtTemplateGuid, 1, NULL, 0, NULL, /*properties=*/EDT_PROP_FINISH, NULL_HINT, /*outEvent=*/ NULL); ASSERT(!res); if(res) { ocrAbort(res); } return NULL_GUID; }
void setupFramework(info_t * info, ocrGuid_t self, u32 maxIt, u32 affCount) { info->self = self; info->i = 0; info->max = maxIt; ocrEdtTemplateCreate(&(info->edtTemplGuids[ITER_IDX]), iterationEdt, 1, 2); ocrEdtTemplateCreate(&(info->edtTemplGuids[SETUP_IDX]), setupEdt, 1, 1); ocrEdtTemplateCreate(&(info->edtTemplGuids[KERNEL_IDX]), kernelEdt, 1, 1); ocrEdtTemplateCreate(&(info->edtTemplGuids[POST_IDX]), postEdt, 1, 1); ocrEdtTemplateCreate(&(info->edtTemplGuids[END_IDX]), endEdt, 1, 1); //TODO don't like this very much but I don't see how to specify //edt affinities otherwise. u32 i = 0; while (i < NB_TMPL) { info->edtAffinities[i] = 0; i++; } info->edtAffinities[SETUP_IDX] = affCount-1; ASSERT(affCount >= 1); info->timer = 0; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { ocrGuid_t e0; ocrEventCreate(&e0, OCR_EVENT_STICKY_T, false); ocrGuid_t terminateEdtGuid; ocrGuid_t terminateEdtTemplateGuid; ocrEdtTemplateCreate(&terminateEdtTemplateGuid, terminateEdt, 0 /*paramc*/, EDT_PARAM_UNK /*depc*/); ocrEdtCreate(&terminateEdtGuid, terminateEdtTemplateGuid, EDT_PARAM_DEF, NULL, 1, NULL_GUID, /*properties=*/EDT_PROP_FINISH, NULL_GUID, /*outEvent=*/ NULL); ocrAddDependence(e0, terminateEdtGuid, 0, DB_MODE_RO); ocrEventSatisfy(e0, NULL_GUID); return NULL_GUID; }
ocrGuid_t finishEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { ocrGuid_t edtTemplateGuid; ocrEdtTemplateCreate(&edtTemplateGuid, remoteEdt, 0, 1); ocrGuid_t eventsGuid[COUNT_EDT]; ocrGuid_t dbsGuid[COUNT_EDT]; u64 i = 0; while(i < COUNT_EDT) { ocrEventCreate(&eventsGuid[i],OCR_EVENT_ONCE_T, EVT_PROP_NONE); ocrGuid_t * dbPtr; ocrDbCreate(&dbsGuid[i], (void **)&dbPtr, sizeof(ocrGuid_t), DB_PROP_SINGLE_ASSIGNMENT, NULL_HINT, NO_ALLOC); dbPtr[0] = eventsGuid[i]; ocrDbRelease(dbsGuid[i]); i++; } // Setup shutdown EDT ocrGuid_t shutdownEdtTemplateGuid; ocrEdtTemplateCreate(&shutdownEdtTemplateGuid, shutdownEdt, 0, COUNT_EDT); ocrGuid_t shutdownEdtGuid; ocrEdtCreate(&shutdownEdtGuid, shutdownEdtTemplateGuid, 0, NULL, EDT_PARAM_DEF, eventsGuid, EDT_PROP_NONE, NULL_HINT, NULL); ocrGuid_t currentAffinity; ocrAffinityGetCurrent(¤tAffinity); ocrHint_t edtHint; ocrHintInit( &edtHint, OCR_HINT_EDT_T ); ocrSetHintValue( & edtHint, OCR_HINT_EDT_AFFINITY, ocrAffinityToHintValue( currentAffinity) ); // Spawn 'COUNT_EDT' EDTs, each satisfying its event i = 0; while(i < COUNT_EDT) { // Create EDTs ocrGuid_t edtGuid; ocrEdtCreate(&edtGuid, edtTemplateGuid, 0, NULL, EDT_PARAM_DEF, &dbsGuid[i], EDT_PROP_NONE, &edtHint, NULL); i++; } return NULL_GUID; }
int main(int argc, const char * argv[]) { ocrConfig_t ocrConfig; ocrGuid_t legacyCtx; ocrParseArgs(argc, argv, &ocrConfig); ocrLegacyInit(&legacyCtx, &ocrConfig); ocrGuid_t rootEdtGuid; ocrGuid_t rootEdtTemplateGuid; ocrEdtTemplateCreate(&rootEdtTemplateGuid, rootEdt, 0 /*paramc*/, 0 /*depc*/); ocrEdtCreate(&rootEdtGuid, rootEdtTemplateGuid, EDT_PARAM_DEF, /*paramv=*/NULL, EDT_PARAM_DEF, /*depv=*/NULL, /*properties=*/0, NULL_HINT, /*outEvent=*/NULL); // This should wait for the EDT to finish ocrLegacyFinalize(legacyCtx, true); return 0; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { PRINTF("Starting mainEdt\n"); ocrGuid_t edt1_template, edt2_template, edt3_template; ocrGuid_t edt1, edt2, edt3, outputEvent1, outputEvent2; //Create templates for the EDTs ocrEdtTemplateCreate(&edt1_template, fun1, 0, 1); ocrEdtTemplateCreate(&edt2_template, fun2, 0, 1); ocrEdtTemplateCreate(&edt3_template, shutdownEdt, 0, 2); //Create the EDTs ocrEdtCreate(&edt1, edt1_template, EDT_PARAM_DEF, NULL, EDT_PARAM_DEF, NULL, EDT_PROP_NONE, NULL_HINT, &outputEvent1); ocrEdtCreate(&edt2, edt2_template, EDT_PARAM_DEF, NULL, EDT_PARAM_DEF, NULL, EDT_PROP_NONE, NULL_HINT, &outputEvent2); ocrEdtCreate(&edt3, edt3_template, EDT_PARAM_DEF, NULL, 2, NULL, EDT_PROP_NONE, NULL_HINT, NULL); //Setup dependences for the shutdown EDT ocrAddDependence(outputEvent1, edt3, 0, DB_MODE_CONST); ocrAddDependence(outputEvent2, edt3, 1, DB_MODE_CONST); //Start execution of the parallel EDTs ocrAddDependence(NULL_GUID, edt1, 0, DB_DEFAULT_MODE); ocrAddDependence(NULL_GUID, edt2, 0, DB_DEFAULT_MODE); return NULL_GUID; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { u64 affinityCount; ocrAffinityCount(AFFINITY_PD, &affinityCount); ASSERT(affinityCount >= 1); ocrGuid_t affinities[affinityCount]; ocrAffinityGet(AFFINITY_PD, &affinityCount, affinities); ocrGuid_t edtAffinity = affinities[affinityCount-1]; ocrGuid_t edtTemplateGuid; ocrEdtTemplateCreate(&edtTemplateGuid, remoteEdt, 2, 0); ocrHint_t edtHint; ocrHintInit( &edtHint, OCR_HINT_EDT_T ); ocrSetHintValue( & edtHint, OCR_HINT_EDT_AFFINITY, ocrAffinityToHintValue( edtAffinity) ); ocrGuid_t edtGuid; u64 edtParamv[2] = {333,555}; ocrEdtCreate(&edtGuid, edtTemplateGuid, EDT_PARAM_DEF, (u64*) &edtParamv, 0, NULL, EDT_PROP_NONE, &edtHint, NULL); return NULL_GUID; }
ocrGuid_t saViolationEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { ocrGuid_t dbGuid = (ocrGuid_t) depv[0].guid; PRINTF("[remote] saViolationEdt: executing, depends on remote DB guid "GUIDF" \n", GUIDA(dbGuid)); TYPE_ELEM_DB v = 1; int i = 0; TYPE_ELEM_DB * data = (TYPE_ELEM_DB *) depv[0].ptr; while (i < NB_ELEM_DB) { ASSERT (data[i] == v++); i++; } PRINTF("[remote] saViolationEdt: illegal local writes to DB/SA\n"); // Being a bad boy and trying to modify the DB/SA content. // There's nothing the runtime can do to prevent spoiling // this node copy (beside making an extra preventing copy). // However the runtime guarantees this won't be written-back // to the DB/SA located on its home node while (i < NB_ELEM_DB) { data[i] *= 2; i++; } ocrDbRelease(dbGuid); u64 affinityCount; ocrAffinityCount(AFFINITY_PD, &affinityCount); ASSERT(affinityCount >= 1); ocrGuid_t affinities[affinityCount]; ocrAffinityGet(AFFINITY_PD, &affinityCount, affinities); ocrGuid_t edtAffinity = affinities[0]; //TODO this implies we know current PD is '0' ocrGuid_t checkerTemplateGuid; ocrEdtTemplateCreate(&checkerTemplateGuid, checkerEdt, 0, 1); ocrHint_t edtHint; ocrHintInit( &edtHint, OCR_HINT_EDT_T ); ocrSetHintValue( & edtHint, OCR_HINT_EDT_AFFINITY, ocrAffinityToHintValue( edtAffinity) ); PRINTF("[remote] saViolationEdt: create checker EDT at DB/SA home node\n"); ocrGuid_t checkerEdtGuid; ocrEdtCreate(&checkerEdtGuid, checkerTemplateGuid, 0, NULL, 1, &dbGuid, EDT_PROP_NONE, &edtHint, NULL); return NULL_GUID; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { // Creates a data block int *k; ocrGuid_t dbGuid; ocrDbCreate(&dbGuid,(void **) &k, sizeof(int), /*flags=*/0, /*location=*/NULL_HINT, NO_ALLOC); *k = 42; // Creates the EDT ocrGuid_t edtGuid; ocrGuid_t taskForEdtTemplateGuid; ocrEdtTemplateCreate(&taskForEdtTemplateGuid, taskForEdt, 0 /*paramc*/, 1 /*depc*/); ocrEdtCreate(&edtGuid, taskForEdtTemplateGuid, EDT_PARAM_DEF, /*paramv=*/NULL, EDT_PARAM_DEF, /*depv=*/&dbGuid, /*properties=*/0, NULL_HINT, /*outEvent=*/NULL); return NULL_GUID; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { u64 affinityCount; ocrAffinityCount(AFFINITY_PD, &affinityCount); ASSERT(affinityCount >= 1); ocrGuid_t affinities[affinityCount]; ocrAffinityGet(AFFINITY_PD, &affinityCount, affinities); ocrGuid_t edtAffinity = affinities[affinityCount-1]; // create local edt that depends on the remote edt, the db is automatically cloned ocrGuid_t remoteEdtTemplateGuid; ocrEdtTemplateCreate(&remoteEdtTemplateGuid, remoteEdt, 0, 0); ocrHint_t edtHint; ocrHintInit( &edtHint, OCR_HINT_EDT_T ); ocrSetHintValue( & edtHint, OCR_HINT_EDT_AFFINITY, ocrAffinityToHintValue( edtAffinity) ); ocrGuid_t edtGuid; ocrEdtCreate(&edtGuid, remoteEdtTemplateGuid, 0, NULL, 0, NULL, EDT_PROP_NONE, &edtHint, NULL); return NULL_GUID; }
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { // Current thread is '0' and goes on with user code. ocrGuid_t latchGuid; ocrEventCreate(&latchGuid, OCR_EVENT_LATCH_T, false); // Creates the EDT ocrGuid_t edtGuid; ocrGuid_t taskForEdtTemplateGuid; ocrEdtTemplateCreate(&taskForEdtTemplateGuid, taskForEdt, 0 /*paramc*/, 1 /*depc*/); ocrEdtCreate(&edtGuid, taskForEdtTemplateGuid, EDT_PARAM_DEF, /*paramv=*/NULL, EDT_PARAM_DEF, /*depv=*/NULL, /*properties=*/0, NULL_GUID, /*outEvent=*/NULL); // Register a dependence between an event and an edt ocrAddDependence(latchGuid, edtGuid, 0, DB_MODE_RO); // decr first and then incr (reaching zero from negative) ocrEventSatisfySlot(latchGuid, NULL_GUID, OCR_EVENT_LATCH_DECR_SLOT); ocrEventSatisfySlot(latchGuid, NULL_GUID, OCR_EVENT_LATCH_INCR_SLOT); return NULL_GUID; }
// The kernel to invoke void domainKernel(ocrGuid_t userKernelDoneEvt, domainSetup_t * setupDbPtr, timestamp_t * timer) { // Setup: DB to use to satisfy the domain kernel's done event ocrGuid_t curAffGuid; ocrAffinityGetCurrent(&curAffGuid); ocrHint_t dbHint; ocrHintInit(&dbHint, OCR_HINT_DB_T); ocrSetHintValue(&dbHint, OCR_HINT_DB_AFFINITY, ocrAffinityToHintValue(curAffGuid)); //TODO why is this not created by the caller as for domainSetup ? ocrGuid_t kernelDbGuid; domainKernel_t * kernelDbPtr; ocrDbCreate(&kernelDbGuid, (void**) &kernelDbPtr, sizeof(domainKernel_t), 0, &dbHint, NO_ALLOC); kernelDbPtr->self = kernelDbGuid; // Kernel's core // Create callback EDT to depend on stop timer event triggered by remote ocrHint_t edtHint; ocrHintInit(&edtHint, OCR_HINT_EDT_T); ocrSetHintValue(&edtHint, OCR_HINT_EDT_AFFINITY, ocrAffinityToHintValue(curAffGuid)); ocrGuid_t stopTpl; ocrEdtTemplateCreate(&stopTpl, stopTimerEdt, 0, 2); ocrGuid_t stopEdt; ocrGuid_t stopEdtDone; ocrEdtCreate(&stopEdt, stopTpl, 0, NULL, 2, NULL, EDT_PROP_NONE, &edtHint, &stopEdtDone); // Stop timer will satisfy the user kernel done event ocrAddDependence(stopEdtDone, userKernelDoneEvt, 0, DB_MODE_NULL); ocrAddDependence(setupDbPtr->stopTimerEvt, stopEdt, 0, DB_MODE_NULL); ocrAddDependence(kernelDbPtr->self, stopEdt, 1, DB_MODE_EW); // Start timer ocrGuid_t remoteEvt = setupDbPtr->remoteLatchEvent; get_time(&kernelDbPtr->startTimer); u64 i; for(i=0; i<NB_SATISFY; i++) { ocrEventSatisfySlot(remoteEvt, NULL_GUID, OCR_EVENT_LATCH_DECR_SLOT); } // Note: Timer stops when the remote latch event got all the satisfy ocrDbRelease(kernelDbGuid); }
ocrGuid_t rootEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { // Build a data-block to be shared with sub-edts u64 * array; ocrGuid_t dbGuid; ocrDbCreate(&dbGuid,(void **) &array, sizeof(u64)*N, 0, NULL_GUID, NO_ALLOC); ocrGuid_t updaterEdtTemplateGuid; ocrEdtTemplateCreate(&updaterEdtTemplateGuid, updaterEdt, 1 /*paramc*/, 1/*depc*/); u64 i = 0; while (i < N) { // Pass down the index to write to and the db guid through params // (Could also be done through dependences) u32 nparamc = 1; u64* nparamv = (u64*) malloc(sizeof(void *)*nparamc); nparamv[0] = i; // Pass the guid we got fron depv to the updaterEdt through depv ocrGuid_t updaterEdtGuid; ocrEdtCreate(&updaterEdtGuid, updaterEdtTemplateGuid, EDT_PARAM_DEF, nparamv, EDT_PARAM_DEF, &dbGuid, 0, NULL_GUID, NULL_GUID); i++; } return dbGuid; }
ocrGuid_t stepA_edt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) { u64 * data = depv[0].ptr; //TODO retrieve data-block guid from depv //END-TODO u64 arraySize = paramv[0]; // Do step A processing: initialize the array u64 i = 0; while(i < arraySize) { data[i] = 0; i++; } // Setup next step ocrGuid_t stepBEdtTemplateGuid; ocrEdtTemplateCreate(&stepBEdtTemplateGuid, stepB_edt, 1 /*paramc*/, 1 /*depc*/); ocrGuid_t stepBEdtGuid; ocrEdtCreate(&stepBEdtGuid, stepBEdtTemplateGuid, EDT_PARAM_DEF, paramv, EDT_PARAM_DEF, &dataGuid, /*prop=*/EDT_PROP_NONE, NULL_GUID, NULL); return NULL_GUID; }