Dummy Decoder Example (was Re: Parallel decoding lesson for you.)

Skybuck Flying skybuck2000 at hotmail.com
Wed Sep 23 11:39:38 CEST 2015


Here is the C version of the example in case your Delphi-to-C skills are not 
so great or you lazy lol =D:

// ParallelDecodingCVersion.cpp : Defines the entry point for the console 
application.
//

#include "stdafx.h"

// Begin of Dummy Decoder Example

const int MaxProcessorCount = 4;

int _tmain(int argc, _TCHAR* argv[])
{
// information stream, input
int Stream[21+(MaxProcessorCount-1)]; // add max processor count to create a 
safe "padding" for reading so no out of bounds/range check errors with 
arrays.

// bits representing fields of data
int a1,a2,a3,a4;
int b1,b2,b3;
int c1;
int d1,d2,d3,d4,d5,d6;

// output
int RowIndex;

int RowCount;
int RowLength[6];
int RowOffset[6];

int DataOffset;

int FieldCount;
int FieldLength;

int Processor[4];

// debug fields
int FieldA;
int FieldB;
int FieldC;
int FieldD;

a1 = 1; a2 = 1; a3 = 1; a4 = 1;
b1 = 1; b2 = 1; b3 = 1;
c1 = 1;
d1 = 1; d2 = 1; d3 = 1; d4 = 1; d5 = 1; d6 = 1;

// compute input fields to compare it later with output fields
FieldA = (a1) | (a2 << 1) | (a3 << 2) | (a4 << 3);
FieldB = (b1) | (b2 << 1) | (b3 << 2);
FieldC = (c1);
FieldD = (d1) | (d2 << 1) | (d3 << 2) | (d4 << 3) | (d5 << 4) | (d6 << 5);

// print field values
printf( "FieldD: %d \n", FieldD );
printf( "FieldA: %d \n", FieldA );
printf( "FieldB: %d \n", FieldB );
printf( "FieldC: %d \n\n", FieldC );

// number of rows
Stream[0] = 6;

// row lengths
Stream[1] = 4;
Stream[2] = 3;
Stream[3] = 3;
Stream[4] = 2;
Stream[5] = 1;
Stream[6] = 1;

// sorted information stream:
// d1a1b1c1d2a2b2d3a3b3d4a4d5d6

// data bits
Stream[7] = d1;
Stream[8] = a1;
Stream[9] = b1;
Stream[10] = c1;
Stream[11] = d2;
Stream[12] = a2;
Stream[13] = b2;
Stream[14] = d3;
Stream[15] = a3;
Stream[16] = b3;
Stream[17] = d4;
Stream[18] = a4;
Stream[19] = d5;
Stream[20] = d6;

// now the decoding algorithm:

// determine number of rows
RowCount = Stream[0];

// extract row lengths
RowLength[0] = Stream[1];
RowLength[1] = Stream[2];
RowLength[2] = Stream[3];
RowLength[3] = Stream[4];
RowLength[4] = Stream[5];
RowLength[5] = Stream[6];

// determine field count
FieldCount = RowLength[0]; // row[0] indicates number of fields.

// I will help out a bit... by leaving this code in ! ;) seems somewhat 
obvious ;)
// first determine data offset properly ! ;) :) 1 for the row count +
// RowCount to skip over row lengths.
DataOffset = 1 + RowCount;

RowOffset[0] = DataOffset;
RowOffset[1] = RowOffset[0] + RowLength[0];
RowOffset[2] = RowOffset[1] + RowLength[1];
RowOffset[3] = RowOffset[2] + RowLength[2];
RowOffset[4] = RowOffset[3] + RowLength[3];
RowOffset[5] = RowOffset[4] + RowLength[4];


// some how the data bits from the stream needs to end up in these 4
// processors so that it produces the same values
// as below:
// fields may be processed in a different order though.

// *** You will need to replace this code with your own code... and
// preferably it should be parallel, fast and somewhat general/scalable. ***
Processor[0] = FieldD;
Processor[1] = FieldA;
Processor[2] = FieldB;
Processor[3] = FieldC;

// print processor values.
printf( "Processor[0]: %d \n", Processor[0] );
printf( "Processor[1]: %d \n", Processor[1] );
printf( "Processor[2]: %d \n", Processor[2] );
printf( "Processor[3]: %d \n\n", Processor[3] );

return 0;
}

// End of Dummy Decoder Example

Bye,
  Skybuck :)




More information about the Python-list mailing list