Install from Source Fatal error: mpi.h: No such file or directory

JuyiLin: <p>I tried installing Pytorch. I follow the commands in  <a href="https://github.com/pytorch/pytorch#installation" class="inline-onebox" rel="noopener nofollow ugc">GitHub - pytorch/pytorch: Tensors and Dynamic neural networks in Python with strong GPU acceleration</a><br>
My gcc version 7.5.0<br>
magma-cuda113  , version ==2.5.2         from conda<br>
But still meet some problems</p>
<pre><code class="lang-auto">Performing C++ SOURCE FILE Test CAFFE2_NEED_TO_TURN_OFF_DEPRECATION_WARNING failed with the following output:
Change Dir: /root/pytorch/build/CMakeFiles/CMakeTmp

Run Build Command(s):/opt/conda/bin/ninja cmTC_b2ec6 &amp;&amp; [1/2] Building CXX object CMakeFiles/cmTC_b2ec6.dir/src.cxx.o
FAILED: CMakeFiles/cmTC_b2ec6.dir/src.cxx.o 
/usr/bin/c++ -DCAFFE2_NEED_TO_TURN_OFF_DEPRECATION_WARNING  -std=c++14 -o CMakeFiles/cmTC_b2ec6.dir/src.cxx.o -c /root/pytorch/build/CMakeFiles/CMakeTmp/src.cxx
/root/pytorch/build/CMakeFiles/CMakeTmp/src.cxx:1:10: fatal error: glog/stl_logging.h: No such file or directory
 #include &lt;glog/stl_logging.h&gt;
          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.

/usr/lib/gcc/x86_64-linux-gnu/7/include/avxintrin.h:1311:1: error: inlining failed in call to always_inline ‘_mm256_set1_ps’: target specific option mismatch
 _mm256_set1_ps (float __A)
 ^~~~~~~~~~~~~~
/root/pytorch/build/CMakeFiles/CMakeTmp/src.c:7:7: note: called from here
     a = _mm256_set1_ps(0);
     ~~^~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.


/root/pytorch/build/CMakeFiles/CMakeTmp/src.c:6:17: error: incompatible types when initializing type ‘__m512i {aka __vector(8) long long int}’ using type ‘int’
ninja: build stopped: subcommand failed.


/root/pytorch/build/CMakeFiles/CMakeTmp/src.c:6:17: error: incompatible types when initializing type ‘__m512i {aka __vector(8) long long int}’ using type ‘int’
ninja: build stopped: subcommand failed.


cc: error: /arch:AVX512: No such file or directory
ninja: build stopped: subcommand failed.

/usr/lib/gcc/x86_64-linux-gnu/7/include/avxintrin.h:1311:1: error: inlining failed in call to always_inline ‘_mm256_set1_ps’: target specific option mismatch
 _mm256_set1_ps (float __A)
 ^~~~~~~~~~~~~~


/root/pytorch/build/CMakeFiles/CMakeTmp/src.c:6:17: error: incompatible types when initializing type ‘__m512i {aka __vector(8) long long int}’ using type ‘int’
ninja: build stopped: subcommand failed.


/root/pytorch/build/CMakeFiles/CMakeTmp/src.c:6:17: error: incompatible types when initializing type ‘__m512i {aka __vector(8) long long int}’ using type ‘int’
ninja: build stopped: subcommand failed.


cc: error: /arch:AVX512: No such file or directory
ninja: build stopped: subcommand failed.

Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /root/pytorch/build/CMakeFiles/CMakeTmp

Run Build Command(s):/opt/conda/bin/ninja cmTC_72b2d &amp;&amp; [1/2] Building C object CMakeFiles/cmTC_72b2d.dir/src.c.o
[2/2] Linking C executable cmTC_72b2d
FAILED: cmTC_72b2d 
: &amp;&amp; /usr/bin/cc  -rdynamic CMakeFiles/cmTC_72b2d.dir/src.c.o -o cmTC_72b2d   &amp;&amp; :
CMakeFiles/cmTC_72b2d.dir/src.c.o: In function `main':
src.c:(.text+0x3e): undefined reference to `pthread_create'
src.c:(.text+0x4a): undefined reference to `pthread_detach'
src.c:(.text+0x56): undefined reference to `pthread_cancel'
src.c:(.text+0x67): undefined reference to `pthread_join'
src.c:(.text+0x7b): undefined reference to `pthread_atfork'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.


/root/pytorch/build/CMakeFiles/CMakeTmp/src.c:3:10: error: #error AVX only on x86_64
         #error AVX only on x86_64
          ^~~~~
ninja: build stopped: subcommand failed.

c++: error: unrecognized command line option '-Wshorten-64-to-32'
c++: error: unrecognized command line option '-Wshorten-64-to-32'
ninja: build stopped: subcommand failed.

c++: error: unrecognized command line option '-wd654'
c++: error: unrecognized command line option '-wd654'
ninja: build stopped: subcommand failed.

c++: error: unrecognized command line option '-Wthread-safety'; did you mean '-fthread-jumps'?
c++: error: unrecognized command line option '-Wthread-safety'; did you mean '-fthread-jumps'?
ninja: build stopped: subcommand failed.


/opt/conda/share/cmake-3.22/Modules/FindMPI/test_mpi.c:1:10: fatal error: mpi.h: No such file or directory
 #include &lt;mpi.h&gt;
          ^~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.


/usr/bin/cc -DUV_LINT_W4  -fopenmp    /W4 -std=gnu90 -o CMakeFiles/cmTC_470b0.dir/src.c.o -c /root/pytorch/build/CMakeFiles/CMakeTmp/src.c
cc: error: /W4: No such file or directory
ninja: build stopped: subcommand failed.


cc: error: /wd4100: No such file or directory
ninja: build stopped: subcommand failed.


Run Build Command(s):/opt/conda/bin/ninja cmTC_cdd19 &amp;&amp; [1/2] Building C object CMakeFiles/cmTC_cdd19.dir/src.c.o
FAILED: CMakeFiles/cmTC_cdd19.dir/src.c.o 
/usr/bin/cc -DUV_LINT_UTF8_MSVC  -fopenmp    /utf-8 -std=gnu90 -o CMakeFiles/cmTC_cdd19.dir/src.c.o -c /root/pytorch/build/CMakeFiles/CMakeTmp/src.c
cc: error: /utf-8: No such file or directory
ninja: build stopped: subcommand failed.


 #include &lt;magma.h&gt;
          ^~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.


/root/pytorch/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:8:19: error: ‘strtod_l’ undeclared (first use in this function); did you mean ‘strtoull’?
   return ((int*)(&amp;strtod_l))[argc];
                   ^~~~~~~~
                   strtoull
/root/pytorch/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:8:19: note: each undeclared identifier is reported only once for each function it appears in
ninja: build stopped: subcommand failed.
</code></pre>

JuyiLin: <p>I found some good material</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://malloc-42.github.io/intro/2021/07/25/Installing-PyTorch/">
  <header class="source">
      <img src="https://malloc-42.github.io/favicon.png" class="site-icon" width="128" height="128">

      <a href="https://malloc-42.github.io/intro/2021/07/25/Installing-PyTorch/" target="_blank" rel="noopener nofollow ugc" title="12:00AM - 25 July 2021">malloc(42) – 25 Jul 21</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://malloc-42.github.io/intro/2021/07/25/Installing-PyTorch/" target="_blank" rel="noopener nofollow ugc">Installing PyTorch From Source!</a></h3>

  <p>Hi Everyone! In this blog post, we’ll be discussing setting up a developer environment for PyTorch. Our goal is to build PyTorch from source on any of the Linux distributions. Presently, I’m working on the Ubuntu 20.04 distribution of Linux in WSL...</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
<div class="youtube-onebox lazy-video-container" data-video-id="AIkvOtHJZeo" data-video-title="Building PyTorch from source (Linux)" data-video-start-time="0" data-provider-name="youtube">
  <a href="https://www.youtube.com/watch?v=AIkvOtHJZeo" target="_blank" rel="noopener nofollow ugc">
    <img class="youtube-thumbnail" src="https://img.youtube.com/vi/AIkvOtHJZeo/maxresdefault.jpg" title="Building PyTorch from source (Linux)" width="690" height="388">
  </a>
</div>

<p>It seems that we need <code>export  $LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH</code></p>