我要评分
获取效率
正确性
完整性
易理解

Compiling and Installing MEGAHIT

Procedure

  1. Use PuTTY to log in to the server as the root user.
  2. Run the following command to go to the source code installation directory:
    cd /path/to/MEGAHIT
  3. Run the following command to decompress the source code package:
    tar -xvf v1.2.9.tar.gz
  4. Run the following command to switch to the folder of the decompressed files:
    cd megahit-1.2.9
  5. Run the following command to modify the CMakeLists.txt file:
    1. Open CMakeLists.txt.
      vi CMakeLists.txt
    2. Press i to enter the insert mode and modify the file as follows:
      Before the modification:
      6     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
      ...
      76 set_target_properties(megahit_core PROPERTIES COMPILE_FLAGS "-mbmi2 -DUSE_BMI2 -mpopcnt")
      77 set_target_properties(megahit_core_popcnt PROPERTIES COMPILE_FLAGS "-mpopcnt")
      After the modification:
      6     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -march=armv8.2-a")
      ...
      76 set_target_properties(megahit_core PROPERTIES COMPILE_FLAGS "")
      77 set_target_properties(megahit_core_popcnt PROPERTIES COMPILE_FLAGS "")
    3. Press Esc, type :wq!, and press Enter to save the file and exit.
  6. Run the following command to switch the directory:
    cd ./src/utils/
  7. Run the following command to copy the header file of the Kunpeng Porting Advisor to the current directory:
    cp /path/to/PORT_ADVISOR/portadv/tools/inline_asm/config/KunpengTrans.h ./
  8. Run the following command to modify cpu_dispatch.h:
    vi cpu_dispatch.h

    The new code content has been marked:

    #if defined(__aarch64__)       // New code
      #include "KunpengTrans.h"     // New code
    #endif      // New code
     
    #ifndef MEGAHIT_CPU_DISPATCH_H
    #define MEGAHIT_CPU_DISPATCH_H
     
    inline bool HasPopcnt() {
      unsigned eax, ebx, ecx, edx;
    #ifdef _MSC_VER
      int cpuid[4];
      __cpuid(cpuid, 1);
      eax = cpuid[0], ebx = cpuid[1], ecx = cpuid[2], edx = cpuid[3];
    #else
    #if defined(__x86_64__)    // New code
      asm volatile("cpuid\n\t"
                   : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
                   : "0"(1));
    #elif defined(__aarch64__)    // New code
      {
        eax = 1;      // New code
        GetSupportedCPUID(&eax,&ebx,&ecx,&edx);     // New code
      }
    #endif  // New code
    #endif
      return ecx >> 23U & 1U;
    }
     
    inline bool HasBmi2() {
      unsigned eax, ebx, ecx, edx;
    #ifdef _MSC_VER
      int cpuid[4];
      __cpuidex(cpuid, 7, 0);
      eax = cpuid[0], ebx = cpuid[1], ecx = cpuid[2], edx = cpuid[3];
    #else
    #if defined(__x86_64__)    // New code
      asm volatile("cpuid\n\t"
                   : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
                   : "0"(7), "2"(0));
    #elif defined(__aarch64__)        // New code
      {
        eax = 7;    // New code
        ecx = 0;    // New code
        GetSupportedCPUID(&eax,&ebx,&ecx,&edx);    // New code
      }
    #endif    // New code
    #endif
      return ebx >> 8U & 1U;
    }
     
    #endif  // MEGAHIT_CPU_DISPATCH_H
  9. Run the following command to switch the directory:
    cd ../kmlib/
  10. Run the following command to modify the kmrns.h file and replace the header file:
    vi kmrns.h
    Before the modification:
    #include <x86intrin.h>
    After the modification:
    #include <sse2neon.h>
  11. Run the following command to copy the sse2neon.h header file to the current directory:
    cp /path/to/SSE2NEON/sse2neon-1.5.0/sse2neon.h ./
  12. Run the following command to create a build folder and go to the folder:
    mkdir /path/to/MEGAHIT/build && cd /path/to/MEGAHIT/build
  13. Run the following commands to perform the compilation and installation:
    CC=`which gcc` CXX=`which g++` cmake -DCMAKE_INSTALL_PREFIX=/path/to/MEGAHIT -DCMAKE_BUILD_TYPE=Release ../
    make -j 16
    make install
  14. Run the following command to load the environment variable:
    export PATH=/path/to/MEGAHIT/bin:$PATH