How to share variable to a team of threads

How to share variable to a team of threads

I am already handle an experiment evaluation of the xeon phi. I want to do the follwoing . "How can I share a variable to a team of threads in the same core using OpenMp

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

It is unclear what do you mean by "team of threads in the same core".

Are you talking about separate OpenMP team for each core?  In this case it is easy to share a variable, many variables are shared by default.

Or are you talking about single big team, and you want subset of threads bound to the same core share a variable which is not visible to other threads of the team?  In this case each subset needs different variable I am afraid. Same variable cannot be shared for only part of the team in OpenMP.

Regards,
Andrey 

Ok , I will explain what I want to do in details. In the case I have 240 thread on the Xeon phi machine and each core have 4 thread. suppose I have matrix multiplication ( A x B = C ) . I want to share a row from matrix A to the 4 thread in the same core and a different column from B to every thread in the same core. Of cource each core will have different row from A and differnet column and Different column from B. how can I do this using OpenMP.

This problem does not related to OpenMP runtime library and to OpenMP in general. This is common programming problem that people work on for ages. There is a lot of research in this area, and many math libraries implemented efficient algorithms of matrix multiplication. You may want to look at Intel(R) Math Kernel Library for example, or some other math library that uses OpenMP parallelization technique.

As to data sharing, if you have a team of 240 OpenMP threads, then as I already explained, once a variable is shared, all 240 threads can access it. What you may want is that threads on same core access same memory while others access another memory (that may be part of the same shared array for example).  This problem again is not an OpenMP problem.  And math libraries try to solve it of cause. The memory access pattern in the program depends on a lot of parameters - programming language, data structures used, size of data, compiler optimizations, etc.  For example, if you keep your big matricies in C array of type float, then it is easy to access different rows from different threads.  But you will have problem with columns, because once a thread touched one column the neighbour colunms may be touched automatically, because they share same cache lines in memory.

Regards,
Andrey 

Leave a Comment

Please sign in to add a comment. Not a member? Join today