<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Integrating a C Subfunction for Optimizing R Code Performance&amp;gt; in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Integrating-a-C-Subfunction-for-Optimizing-R-Code-Performance-gt/m-p/1526558#M35165</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I have an existing R script that performs various operations, and I'm looking to create a C sub function&amp;nbsp;to optimize a specific part of it. My goal is to integrate this C sub function&amp;nbsp;within R Desktop for improved performance and efficiency.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example, let's assume that I want to sum the elements obtained by multiplying the vector x and y. In R, I can achieve this with the following code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# R code
x &amp;lt;- c(1, 2, 3)
y &amp;lt;- c(4, 5, 6)
z &amp;lt;- sum(x * y)   &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The same operation using oneMKL can be performed like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;mkl.h&amp;gt;
int main() {
    double x[] = {1.0, 2.0, 3.0};
    double y[] = {4.0, 5.0, 6.0};
    double z;
    // Perform vector multiplication and summation using Intel MKL
    z = cblas_ddot(3, x, 1, y, 1);
    printf("Result: %lf\n", z);
    return 0;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;After compiling the .c function using CMD, I get:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;C:\Program Files (x86)\Intel\oneAPI&amp;gt;cd C:/Users/Administrator/Desktop
C:\Users\Administrator\Desktop&amp;gt;icx -o example example.c /Qmkl /MD
Intel(R) oneAPI DPC++/C++ Compiler for applications running on Intel(R) 64, Version 2023.1.0 Build 20230320
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

C:\Users\Administrator\Desktop&amp;gt;example.exe
Result: 32.000000&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What I want to do is replace the 4th line of the Rscript code with a .c function. I'm facing two problems:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1) Convert the C Function for General Inputs:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I don't know if I have defined the function correctly.&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;mkl.h&amp;gt;

void multiplyAndSum(double *x, double *y, int length, double *result) {
    *result = cblas_ddot(length, x, 1, y, 1);
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;STRONG&gt;2) Calling the C Function in R:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I don't know how to call the .c function in step 1 within R. Is there a way to compile the function and run it explicitly within R Desktop, without using the command prompt (cmd)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please, I understand that my question may be quite basic, but my knowledge is limited. I would greatly appreciate a step-by-step answer, ideally.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Sep 2023 06:15:29 GMT</pubDate>
    <dc:creator>Fio</dc:creator>
    <dc:date>2023-09-22T06:15:29Z</dc:date>
    <item>
      <title>Integrating a C Subfunction for Optimizing R Code Performance&gt;</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Integrating-a-C-Subfunction-for-Optimizing-R-Code-Performance-gt/m-p/1526558#M35165</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have an existing R script that performs various operations, and I'm looking to create a C sub function&amp;nbsp;to optimize a specific part of it. My goal is to integrate this C sub function&amp;nbsp;within R Desktop for improved performance and efficiency.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example, let's assume that I want to sum the elements obtained by multiplying the vector x and y. In R, I can achieve this with the following code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# R code
x &amp;lt;- c(1, 2, 3)
y &amp;lt;- c(4, 5, 6)
z &amp;lt;- sum(x * y)   &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The same operation using oneMKL can be performed like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;mkl.h&amp;gt;
int main() {
    double x[] = {1.0, 2.0, 3.0};
    double y[] = {4.0, 5.0, 6.0};
    double z;
    // Perform vector multiplication and summation using Intel MKL
    z = cblas_ddot(3, x, 1, y, 1);
    printf("Result: %lf\n", z);
    return 0;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;After compiling the .c function using CMD, I get:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;C:\Program Files (x86)\Intel\oneAPI&amp;gt;cd C:/Users/Administrator/Desktop
C:\Users\Administrator\Desktop&amp;gt;icx -o example example.c /Qmkl /MD
Intel(R) oneAPI DPC++/C++ Compiler for applications running on Intel(R) 64, Version 2023.1.0 Build 20230320
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

C:\Users\Administrator\Desktop&amp;gt;example.exe
Result: 32.000000&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What I want to do is replace the 4th line of the Rscript code with a .c function. I'm facing two problems:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1) Convert the C Function for General Inputs:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I don't know if I have defined the function correctly.&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;mkl.h&amp;gt;

void multiplyAndSum(double *x, double *y, int length, double *result) {
    *result = cblas_ddot(length, x, 1, y, 1);
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;STRONG&gt;2) Calling the C Function in R:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I don't know how to call the .c function in step 1 within R. Is there a way to compile the function and run it explicitly within R Desktop, without using the command prompt (cmd)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please, I understand that my question may be quite basic, but my knowledge is limited. I would greatly appreciate a step-by-step answer, ideally.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 06:15:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Integrating-a-C-Subfunction-for-Optimizing-R-Code-Performance-gt/m-p/1526558#M35165</guid>
      <dc:creator>Fio</dc:creator>
      <dc:date>2023-09-22T06:15:29Z</dc:date>
    </item>
    <item>
      <title>Re:Integrating a C Subfunction for Optimizing R Code Performance&gt;</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Integrating-a-C-Subfunction-for-Optimizing-R-Code-Performance-gt/m-p/1527755#M35189</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks for posting in Intel communities.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Please refer to the below links for compiling R code with MKL, extended support, and other linking-related details.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Linking Intel MKL to R:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.intel.com/content/www/us/en/developer/articles/technical/quick-linking-intel-mkl-blas-lapack-to-r.html" target="_blank"&gt;https://www.intel.com/content/www/us/en/developer/articles/technical/quick-linking-intel-mkl-blas-lapack-to-r.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Building R with the Intel® Math Kernel Library (Intel® MKL) BLAS and LAPACK to improve the performance of those parts of R that rely on matrix computations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.intel.com/content/www/us/en/developer/articles/technical/extending-r-with-intel-mkl.html" target="_blank"&gt;https://www.intel.com/content/www/us/en/developer/articles/technical/extending-r-with-intel-mkl.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;How to use the BLAS and LAPACK libraries within Intel® oneAPI Math Kernel Library (oneMKL) to improve the performance of R.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.intel.com/content/www/us/en/developer/articles/technical/using-onemkl-with-r.html" target="_blank"&gt;https://www.intel.com/content/www/us/en/developer/articles/technical/using-onemkl-with-r.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jilani&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 26 Sep 2023 15:21:49 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Integrating-a-C-Subfunction-for-Optimizing-R-Code-Performance-gt/m-p/1527755#M35189</guid>
      <dc:creator>IntelSupport</dc:creator>
      <dc:date>2023-09-26T15:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Integrating a C Subfunction for Optimizing R Code Performance&gt;</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Integrating-a-C-Subfunction-for-Optimizing-R-Code-Performance-gt/m-p/1527804#M35191</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thank you very much for the help and the links.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If I'm not mistaken, the first and third links provide instructions for Linux, while the second one is for Windows. However, I'm sincerely sorry, but I'm having trouble understanding what I need to do. I apologize deeply, but so far, I've been working with MATLAB and Intel Parallel Studio, and compiling with them was easier for me. I've invested a lot of time into this, but I'm still struggling. Could you please provide more detailed instructions? I would greatly appreciate it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My environment variables are displayed in the image below. Perhaps this information could be helpful for you to assist me.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2023-09-14 141741.png" style="width: 400px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/46171iB27E76BC92FDB975/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="Screenshot 2023-09-14 141741.png" alt="Screenshot 2023-09-14 141741.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; Thank you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 16:38:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Integrating-a-C-Subfunction-for-Optimizing-R-Code-Performance-gt/m-p/1527804#M35191</guid>
      <dc:creator>Fio</dc:creator>
      <dc:date>2023-09-26T16:38:14Z</dc:date>
    </item>
    <item>
      <title>Re:Integrating a C Subfunction for Optimizing R Code Performance&gt;</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Integrating-a-C-Subfunction-for-Optimizing-R-Code-Performance-gt/m-p/1529847#M35229</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks for sharing your requirement details. We are looking into your issue internally. We will get back to you soon with an update.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jilani&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 03 Oct 2023 12:19:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Integrating-a-C-Subfunction-for-Optimizing-R-Code-Performance-gt/m-p/1529847#M35229</guid>
      <dc:creator>IntelSupport</dc:creator>
      <dc:date>2023-10-03T12:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: Integrating a C Subfunction for Optimizing R Code Performance&gt;</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Integrating-a-C-Subfunction-for-Optimizing-R-Code-Performance-gt/m-p/1535817#M35341</link>
      <description>&lt;P&gt;Hi Fio,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apologies for delay in the response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We regret to say that we will not be able to support you on these R related queries, since we aren’t “R” experts. We’d only be able to support issues only related to Intel products.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have any query on Intel products, then please raise a new thread in the appropriate forum and we’d be happy to support you. Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Jilani&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 11:27:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Integrating-a-C-Subfunction-for-Optimizing-R-Code-Performance-gt/m-p/1535817#M35341</guid>
      <dc:creator>IntelSupport</dc:creator>
      <dc:date>2023-10-20T11:27:23Z</dc:date>
    </item>
    <item>
      <title>Re:Integrating a C Subfunction for Optimizing R Code Performance&gt;</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Integrating-a-C-Subfunction-for-Optimizing-R-Code-Performance-gt/m-p/1537911#M35369</link>
      <description>&lt;P&gt;Hi Fio,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;This thread will no longer be monitored by Intel. If you need further assistance, please post a new thread. We are going ahead and closing this thread.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jilani&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 27 Oct 2023 09:38:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Integrating-a-C-Subfunction-for-Optimizing-R-Code-Performance-gt/m-p/1537911#M35369</guid>
      <dc:creator>IntelSupport</dc:creator>
      <dc:date>2023-10-27T09:38:48Z</dc:date>
    </item>
  </channel>
</rss>

