I was working on network sort (for arrays smaller than 8) and noticed that all the algorithms focus on its ability to allow parallel operations. Here is one such set for an array of size 5.
#define SWAP(x,y) if (data[y] < data[x]) { int tmp = data[x]; data[x] = data[y]; data[y] = tmp; }
//Parallelizable
SWAP(1, 2);
SWAP(4, 5);
//Parallelizable
SWAP(0, 2);
SWAP(3, 5);
//Parallelizable
SWAP(0, 1);
SWAP(3, 4);
SWAP(2, 5);
//Parallelizable
SWAP(0, 3);
SWAP(1, 4);
//Parallelizable
SWAP(2, 4);
SWAP(1, 3);
//Parallelizable
SWAP(2, 3);
I was working with long int
arrays (So each element is 8 bytes in size). So is there any easy way to parallelize these operations in C ? Is there any hardware specific commands I can use to achieve this (SIMD, ASM(x86) etc.)