Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7873 Discussions

How can I work with local arrays and threads

Eugin_B_
Beginner
206 Views

Hi All!

I have VS2013+Intel Parallel Studio XE 2015+TBB 4.3

My current code has many functions that has local stack allocations by exampe

void fnc() {

  int arr[1024];

   .............

}

when I started use fnc() in parallel for (it is some form of parallel execution) I got bad concurrent perfomance according to VTune analyser

I done some replacement for the code: int *arr = malloc(sizeof(int) * 1024). malloc I got versus from tbb of course. In the result I got very good concurrent execution. Really I can't understand why local stack allocation has concurrency problems. Can anyone describe the problem? Has this issue easy solution?

Thanks! Sorry for my bad english!

0 Kudos
3 Replies
jimdempseyatthecove
Black Belt
206 Views

If the speed differs, but the results are correct, then suspect it is an alignment issue. You can align the stack local array using:

Windows* OS:

__declspec(align(16)) int arr[1024];
 


Linux* OS:

int arr[1024] __attribute__((aligned(16)));


FWIW I whish the standards committee would adopt a uniform way of doing this.

Jim Dempsey

0 Kudos
jimdempseyatthecove
Black Belt
206 Views

Thanks for pointing this out to me. Now I can start modernizing my alignment directives/attributes.

It still bugs me that C++11 and C11 use different keywords, same issue with __int32, int32_t, int32, etc...

Jim Dempsey

0 Kudos
Eugin_B_
Beginner
206 Views

Thank you for your replies. I tested alignment directives but without any changes in the results.

I tried to create the simple example to show the issue more detailed but I found that all is not so simple and easy. I will investigate it and give you back with additional info if my question still is actual

0 Kudos
Reply