<div dir="ltr"><div>Hello everyone,</div><div><br></div><div>I was writing a new runtime routine to integrate with intel openMP runtime. My function call is pretty like the calling of, "omp_set_num_threads(4);"</div><div><div><span style="white-space:pre"> </span></div><div><b>omp_set_my_threads(8);</b></div><div><b>omp_set_data_bind(&bindvariable);</b></div><div><b><br></b></div><div><b>my goal here is to set/provide (to runtime) a integer value and an address location through runtime routine call. </b></div><div><b><br></b></div><div><b>What I did: </b></div><div>I have made a shadow copy like the omp_set_num_thread() function implementation; it generates the function prototype as below <b>in the omp.h header file:</b> </div><div>extern void __KAI_KMPC_CONVENTION omp_set_num_threads (int);<br></div><div><br></div><div>extern void __KAI_KMPC_CONVENTION omp_set_data_bind (void *);</div><div>extern void __KAI_KMPC_CONVENTION omp_set_my_threads (int);</div><div><br></div><div><br></div><div>and in my program I am calling like: </div><div><br></div><div>int main(){</div><div>....</div><div><br></div><div><div>omp_set_num_threads(4);</div><div><span class="" style="white-space:pre"> </span></div><div><b>omp_set_my_threads(8);</b></div><div><b>omp_set_data_bind(&bindvariable);</b></div><div><span class="" style="white-space:pre"> </span>#pragma omp parallel</div><div><span class="" style="white-space:pre"> </span>{</div></div><div> ---</div><div> }</div><div><br></div><div>}</div><div><br></div><div>Compile with CLANG (LLVM) the IR code generates the function call as: <b>call void @omp_set_my_threads(i32 8)</b></div><div><b><br></b></div><div><b>but while I am going to compile it gives me the error as: </b></div><div><b><br></b></div><div><b><div style="color:rgb(255,0,0)">/tmp/XXXa.o: In function `main':</div><div style="color:rgb(255,0,0)">XXXa.c:(.text+0x403): undefined reference to `omp_set_my_threads'</div><div style="color:rgb(255,0,0)">clang-3.5: error: linker command failed with exit code 1 </div><div style="color:rgb(255,0,0)"><br></div><div><font color="#0000ff">CAN YOU PLEASE COMMENT WHAT I AM MISSING HERE ..? </font></div><div><font color="#0000ff"><br></font></div><div><font color="#000000">thank you very much in advance..!!</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">- Raju</font></div></b></div><div><b><br></b></div><div><b><br></b></div><div><span class="" style="white-space:pre"> </span></div></div><div><br></div><div><br></div><div><br></div><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 15, 2015 at 11:02 AM, Churbanov, Andrey <span dir="ltr"><<a href="mailto:Andrey.Churbanov@intel.com" target="_blank">Andrey.Churbanov@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div lang="RU" link="#0563C1" vlink="#954F72">
<div>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Hello,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">If you print information from __kmp_task_alloc() function, you cannot find your data in the structures.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">The reason is that this routine only allocates space requested by the compiler and initializes its own runtime-related
info, and if you examine the space allocated for shareds you can only find uninitialized memory there.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">The addresses of shared variables are put into allocated memory by the compiler later, AFTER the __kmp_task_alloc() call.
E.g. the array of shareds should already be initialized in the __kmp_omp_task() call. But I doubt you can rely on particular location of any shared variable in the array of shareds, it is compiler’s decision where to place your particular variable’s address,
and it may or may not be the first in the array of shareds. E.g. compiler can insert its own auxiliary data before user’s data.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Regards,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Andrey<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><a name="1144782762______replyseparator"></a><b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif"> Openmp-dev [mailto:<a href="mailto:openmp-dev-bounces@lists.llvm.org" target="_blank">openmp-dev-bounces@lists.llvm.org</a>]
<b>On Behalf Of </b>Rezaul Karim Raju via Openmp-dev<br>
<b>Sent:</b> Tuesday, December 15, 2015 8:47 AM<br>
<b>To:</b> <a href="mailto:openmp-dev@lists.llvm.org" target="_blank">openmp-dev@lists.llvm.org</a>; <a href="mailto:openmp-commits@lists.llvm.org" target="_blank">openmp-commits@lists.llvm.org</a><br>
<b>Subject:</b> [Openmp-dev] Intel OpenMP Runtime & LLVM [kmp_tasking.c]: Problem to access SHARED VARIABLE DATA LOCATION<u></u><u></u></span></p><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Dear concern, <u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Please consider the source code(openmp c code) snippet as below: <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">--- code snippet ---<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">int a1, b1, c1, N;<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Initially address of a1:= 0x7fff9bd58304 <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">omp_set_num_threads(2);<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> #pragma omp parallel<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> #pragma omp single<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> // task one: a1=b1+c1;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> #pragma omp task shared(a1) firstprivate(b1,c1)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> a1 = a1 + b1 + c1;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> }<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> }<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> }<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">In the above openMP code task construct contains shared variable (a1), I AM INTERESTED TO FIND THE SHARED VARIABLE OF TASK DATA IN RUNTIME TASK ALLOCATION.
<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I am looking into the source code of Intel OpenMP Runtime, my openmp code is compiled with LLVM. In the LLVM IR, @__kmpc_omp_task_alloc( ...) calls runtime function kmp_task_alloc(), source code is here: under the <src> directory, Kmp_tasking.c
<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I am trying to access the "shared variable data location for a task" which is as below: <u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">kmp_task_t *<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">__kmp_task_alloc(...){<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">kmp_task_t *task;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">kmp_taskdata_t *taskdata;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">// Calculate shared structure offset including padding after kmp_task_t struct<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> // to align pointers in shared struct<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> shareds_offset = sizeof( kmp_taskdata_t ) + sizeof_kmp_task_t;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> shareds_offset = __kmp_round_up_to_val( shareds_offset, sizeof( void * ));<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">// Avoid double allocation here by combining shareds with taskdata<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> #if USE_FAST_MEMORY<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> taskdata = (kmp_taskdata_t *) __kmp_fast_allocate( thread, shareds_offset + sizeof_shareds );<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> #else /* ! USE_FAST_MEMORY */<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> taskdata = (kmp_taskdata_t *) __kmp_thread_malloc( thread, shareds_offset + sizeof_shareds );<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> #endif /* USE_FAST_MEMORY */<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal">task = KMP_TASKDATA_TO_TASK(taskdata);<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">if (sizeof_shareds > 0) {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> // Avoid double allocation here by combining shareds with taskdata<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> task->shareds = & ((char *) taskdata)[ shareds_offset ];<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">printf("task->shareds address original:= %p address of pointer it points to := %p\n", & ((char *) taskdata)[ shareds_offset ], *task->shareds);<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> }<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal">}<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">here, <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">typedef struct kmp_task { /* GEH: Shouldn't this be aligned somehow? */<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> void * shareds; /**< pointer to block of pointers to shared vars */<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">}<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">But, task->shareds = & ((char *) taskdata)[ shareds_offset ]; which is a pointer to block of pointers to shared variables, if I print the shared variable pointing address(which should be the address of a1:= 0x7fff9bd58304) <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">IT PRINTS DIFFERENT ADDRESS: <0x1fe0ef0><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">NEED TO GET THE ADDRESS OF TASK'S SHARED VARIABLE ADDRESS FROM RUNTIME.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">appreciate your comment and help. Thanking you.<u></u><u></u></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:10pt;color:rgb(204,204,204)">------------------------</span><u></u><u></u></p>
</div>
<p class="MsoNormal"><span style="font-size:10pt;color:rgb(153,153,153)">RaJu, Rezaul Karim<br>
Graduate Student (PhD) | Computer Science | University of Houston</span><u></u><u></u></p>
<div>
<p class="MsoNormal"><span style="font-size:10pt;color:rgb(153,153,153)">Research in High Performance Computing Tools </span><u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:10pt;color:rgb(153,153,153)">Houston, Texas-77004</span><u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div></div></div>
<p><br>--------------------------------------------------------------------<br>Joint Stock Company Intel A/O<br>Registered legal address: Krylatsky Hills Business Park, <br>17 Krylatskaya Str., Bldg 4, Moscow 121614, <br>Russian Federation</p><p>This e-mail and any attachments may contain confidential material for<br>the sole use of the intended recipient(s). Any review or distribution<br>by others is strictly prohibited. If you are not the intended<br>recipient, please contact the sender and delete all copies.</p>
</div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><font face="times new roman, serif" size="2" color="#cccccc">------------------------</font></div><font face="times new roman, serif" size="2" color="#999999">RaJu, Rezaul Karim<br>Graduate Student (PhD) | Computer Science | University of Houston</font><div><font face="times new roman, serif" size="2" color="#999999">Research in High Performance Computing Tools </font><div><div><font face="times new roman, serif" size="2" color="#999999">Houston, Texas-77004</font></div></div></div></div></div>
</div></div>