Parallel with only one core?

2

I'm wanting to parallelize an application, in this case a 'cosine similarity' calculation, but the machine I'm working on has only one core. Paralleling this calculation with only one core will have some significant gain?

    
asked by anonymous 09.01.2018 / 13:36

1 answer

3

As you yourself suspect, no, you will not have any performance increase in this case.

If the machine has hyperthreading - that is, two "visible" colors but only one physical core in this case, it would depend on the CPU model - it would have to have two internal FPUs, and a good job would have to be done in the allocating tasks to the parallel overhead does not stay above the minimum gain you could have there.

But here we go to other considerations: do you want to "parallel" or want to "accelerate" your calculation? Paralleling to learn how to do this is one thing. Just wanting more performance is another.

If you are using Python, and expressing pure Python operations (and not using something like NumPy, which has code for numeric processing), your program may be 1000 to 10000 times slower than the same program running in native code.

If you instead of running your program in normal Python, use Pypy - the "Python done in Python", which has a mechanism of JIT, will gain about 10 times in purely numeric code performance.

If you use Cython - a Python super-set that compiles the program into C, and allows you to define the types of your (so their numbers can be a native int64 instead of an int object of Python), it can get pretty close to the native performance (ie more than 1000 times faster).

Having said all that, you can "parallelize" the code by leveraging the capabilities that modern CPUs have for numeric calculations even in a single core - that is, if you can write your code in a way that uses the AVX Intel, for example. (Of breaking any module that let you take advantage of this numeric CPU parallelism will also be using native numbers, offering many of the gains described above). One of the projects that seems to be active doing this is PyOpenCL - which can use OpenCL to make use of the advanced features of your CPU or even use your video card.

    
09.01.2018 / 16:24