Parallel sorting of small networks

I worked on sorting the network (for arrays less than 8) and noticed that all the algorithms focused 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 worked with arrays long int(so each element is 8 bytes in size). So, is there an easy way to parallelize these operations in C? Are there any hardware specific commands that I can use to achieve this (SIMD, ASM (x86), etc.)

+4
source share
1 answer

, , :

#define SWAP(x, y) {                        \
    int dx = data[x];                       \
    data[x] = dx < data[y] ? dx : data[y];  \
    data[y] ^= dx ^ data[x];                \
}

, SWAP 5 GCC Clang . , parallelism.

xor , SWAP, , , xor. , , " , " " , ", . 8 ~ 5 , .

+2

All Articles