Why would Eclipse C ndk jni execution speed be 6 times slower than gcc shell? - android-ndk

I have a program which uses C ndk subroutines in jni which processes a 3204x2406 image file which takes 6+ seconds when run *(without debug) by eclipse with NDK_DEBUG=0.
I've got the same code compiled with GCC on the android running in the shell at under 1 second.
The code consists of loops and integer math. Both the eclipse ndk program and the gcc shell program access the exact same file from the exact same location. There are no trace statements within the 6 seconds. The only external calls is 2406 read statements.
The eclipse is the google integrated download 21.0.0, which is uses Juno 4.2.1 and c/c++ 8.1.1. And yes, i've restarted eclipse and cleaned the project.
I'm now thinking about trying to call or link to the GCC code, but keep feeling like I must be missing something silly.

Related

How to run some code compiled in DLL on GPU

I have program written in C++ and compiled as DLL and theres some code in my program that's difficult to compute on CPU so I wanna run it on GPU instead, is it somehow possible ? I don't know if I will have to rewrite my entire project because of CUDA or other toolkits.
Also my program must be in DLL not EXE

SEGILL android ndk code

I have developed a library which I have testing on an x86-64 bit machine and it works and passes tests successfully. When I put it in my android application, the code stops in a constructor that just initializes all its variables to their default values (pointers get assigned to null, booleans to false...). I have set the target for x86-64 bit so I am sure it's not a problem of deploying a different architecture. How can I find out the root of the problem because if I do comment out the initialization in the constructor, it will execute a good amount of code before giving a SEGILL error again? I am using android 8 x64 bit intel image in the emulator. Also, the log cat doesn't show anything, the only error is the SEGILL.
It seems that most of the time, doing some pointer manipulation causes the problem. Simply initializing pointers with null or new causes the app to crash.
Instead of enabling SSE, I enabled avx which is not supported by android and therefore clang optimized some parts by using avx which resulted in SIGILL.

MATLAB 32-bit executable file crashing with a function of Optimization Toolbox

I am working on a MATLAB project which we want to export as .exe. The resulting file must then be able to run on both 32 and 64-bits Windows 7 PCs.
After a little research we realized this problem was easier to approach by developing on a 32-bit version of MATLAB building then a 32-bits .exe file.
Till this point, all our development was being carried in the 64-bits version of MATLAB. With it we had been able to successfully generate and run 64-bits .exe versions.
Now that we switched to MATLAB 32-bits, however, and we generate the .exe, something goes wrong and the following error is shown:
Undefined function ‘fmincon’ for input arguments of type ‘function handle’.
This is the line of code in which fmincon first appears:
Options = optimoptions('fmincon', 'DiffMinChange', 10);
A few remarks:
The same scripts which worked on MATLAB 64-bits also work on MATLAB
32-bits. Within the MATLAB environment, everything runs smoothly.
The scripts (with the same exact code) can still be made executable on MATLAB 64-bits without any problem.
In both cases, we properly installed the runtime required for the MATLAB executable to be run on the PC.
We have tried to run the 32-bits .exe in both 64-bits and 32-bits machines with the same result.
Is it possible that the 32-bits version of MATLAB's deployed executable has problems dealing with functions from the Optimization Toolbox (as fmincon is)?
What else could be the cause of this problem? Does anyone have an idea how to fix it?
The problem was only solved thanks to MATLAB's support. This is related to a bug in version R2014a, explained and patched in this Mathworks link.

MSVC 2010 - Error 0xc000007b when building in x64

The title is pretty straightforward - I can't get anything at all to run when building in x64 and I get a message box with this error code. Do you know what may be the problem here?
This is STATUS_INVALID_IMAGE_FORMAT, you can find these error codes listed in the ntstatus.h SDK header file.
It is certainly strongly correlated with building x64 code. You'll get this status code whenever your program has a dependency on 32-bit code, particularly in a DLL. Your program will fail to start when it tries to load the DLL at startup, a 64-bit process cannot contain any 32-bit code. Or the other way around, a 32-bit process trying to load a 64-bit DLL.
Review all the dependencies for your program, particularly the import libraries you link. Everything must be built to target x64. You can use SysInternals' ProcMon utility to find the DLL that fails to load, useful in case this is a DLL Hell problem.
Just an addition to the correct answer above: also check you .manifest-files (resp. #pragma comment(linker,"/manifestdependency...) and make sure that you have processorArchitecture='x86' for 32-bit and processorArchitecture='amd64' for x64 code.

GCC v/s Visual studio run time differences

I have written a C++ code for a vehicle routing project. On my dell laptop I have both Ubuntu and Windows 7 installed. When i run my code in a gcc compiler on UNIX platform it runs at least 10x faster than the exact same code on Visual C++ 2010 on the windows OS (both of them on the same machine). This is not just for one particular code, turns out this happens for almost every C++ code i have been using.
I am assuming there is an explanation to such a large differences in runtimes and why gcc out performs visual C++ run time wise. Could anyone enlighten me on this?
Thanks.
In my experience, both compilers are fairly equal, but you have to watch out for a few things:
1. Visual Studio defaults to stack-checking on, which means that every function starts with a small amount of "memset" and ends with a small amount of "memcmp". Turn that off if you want performance - it's great for catching when you write to the 11th element of a ten element array.
2. Visual studio does buffer overflow checking. Again, this can add a significant amount of time to the execution.
See: Visual Studio Runtime Checks
I believe these are normally enabled in debug mode, but not in release builds, so you should get similar results from release builds and -O2 or -O3 optimized builds on gcc.
If this doesn't help, then perhaps you can give us a small (compilable) example, and the respective timings.

Resources