Choose C binary file according to environment

I have compiled my code with certain flags (-Os, -O2, -march = native, and combinations thereof) to provide faster execution times.

But my problem is that I don't always run on the same machine (because there are several different machines in my lab). Sometimes I run on MacOS or Linux (both with different OS versions).

I wonder if there is a way to determine which binary will run depending on the environment the binary will run in (I mean cache size, processor cores, and other properties of a particular machine). In other words, how do I choose (when the program loads) a faster binary (previously compiled with different target binaries and instruction set extensions) depending on the particular computer being used?

Thanks in advance.

+1


source to share


4 answers


You can pre-create a bunch of executables and choose one according to the environment variable or things like uname

. The best approach to the problem is to choose a toolchain capable of performing JIT, setup time optimization, and / or runtime optimization such as llvm.



+1


source


What you are talking about is called Bold Binary (not FAT, acronym). From Wikipedia 1 :

A bold binary (or multiarchitectural) binary is a computer-executable program that has been extended (or "fed") with code native to a variety of instruction sets that can therefore execute on multiple types of processors. This causes the file to be larger than a regular single architecture binary, thus the name.



On a quick look at it, there doesn't seem to be much support (see this question from Programmer StackExchange for more information). Apple implemented this briefly when moving from PowerPC to Intel, but it hasn't seemed to be studied since.

Technically, bold binaries refer to a single binary that can run on multiple architectures ... but I guess the premise will be used for a single binary that runs on multiple OSs. And it goes back to the point Bizkit made in his / her / zir answer - usually you will compile the source code for the environment you are in ahead of time.

+4


source


Is there a reason why you can't just recompile the source code on every machine? Compilers have already been written and optimized for just this kind of material. Just recompile the source code on that machine architecture and you have a binary that works great on that machine.

0


source


If you want your code to tune to the cache size of the machine you are running on, check out the way the Automatically Tuned Linear Algebra Software (ATLAS) does. When you compile it, it runs several tests to determine what size to use to cache-block its loops and places them in a header file.

0


source







All Articles