目录

Julia

misaraty 更新 | 2024-02-16
前言
Julia是MIT设计的高性能数值计算语言。2017年,Julia进入了Petaflop俱乐部。它既有如Python、Matlab的语法便捷性,也有媲美C、Fortran的运行速度。

安装

  • 下载Julia。选择Generic Linux binaries版本。直接解压,并在~/bin下输入julia即可。

Windows

  • 配置环境变量。

    鼠标点击此电脑-属性-高级系统设置-环境变量-系统变量,在Path中新增,

1
C:\Users\lenovo\AppData\Local\Programs\Julia-1.9.2\bin

          或,

          一键增加环境变量,add_path.bat

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
@echo off
set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
set evname1=JULIA_DEPOT_PATH
set evname2=JULIA_PKG_SERVER
set path1=%~dp0bin
set path2=%~dp0.julia
set path3=https://mirrors.sjtug.sjtu.edu.cn/julia/
reg add "%regpath%" /v %evname1% /d %path2% /f
setx /m path "%path%;%path1%"
reg add "%regpath%" /v %evname2% /d %path3% /f
pause>nul

          一键删除环境变量,delete_path.bat

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
@echo off
setlocal enabledelayedexpansion
set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
set evname1=JULIA_DEPOT_PATH
set evname2=JULIA_PKG_SERVER
set path1=%~dp0bin
reg delete "%regpath%" /v "%evname1%"  /f
setx /m path "!path:%path1%;=!"
reg delete "%regpath%" /v "%evname2%"  /f
pause>nul

          修改C:\Users\lenovo\AppData\Local\Programs\Julia-1.9.2\etc\julia\startup.jl

1
2
3
# This file should contain site-specific commands to be executed on Julia startup;
# Users may store their own personal commands in `~/.julia/config/startup.jl`.
ENV["JULIA_PKG_SERVER"]="https://mirrors.sjtug.sjtu.edu.cn/julia/"
  • 显示Julia环境变量,
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
julia> versioninfo()
Julia Version 1.9.2
Commit e4ee485e90 (2023-07-05 09:39 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 24 × 12th Gen Intel(R) Core(TM) i9-12900HX
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, alderlake)
  Threads: 1 on 24 virtual cores
Environment:
  JULIA_PKG_SERVER = https://mirrors.sjtug.sjtu.edu.cn/julia/

Linux

  • 使用Intel MKL,进行源码编译安装1
1
2
3
4
5
6
7
8
9
cd /opt/ohpc/pub/apps/julia-1.10.1

echo "USEICC = 0" >> Make.user
echo "USEIFC = 0" >> Make.user
echo "USE_INTEL_MKL = 1" >> Make.user
echo "USE_INTEL_LIBM = 1" >> Make.user
​
make -j $((`nproc`-1))
# make -j $((`nproc`-1)) 1> build_log.txt 2> build_error.txt
  • 配置环境变量。

    修改.bashrc

1
2
3
# julia
export PATH=$PATH:/opt/ohpc/pub/apps/julia-1.10.1/bin
export JULIA_PKG_SERVER=https://mirrors.sjtug.sjtu.edu.cn/julia/
  • 显示Julia环境变量,
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
julia> versioninfo()
Julia Version 1.10.1
Commit 7790d6f064 (2024-02-13 20:41 UTC)
Build Info:

    Note: This is an unofficial build, please report bugs to the project
    responsible for this build and not to the Julia project unless you can
    reproduce the issue using official builds available at https://julialang.org/downloads

Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: 40 × Intel(R) Xeon(R) Silver 4210 CPU @ 2.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, cascadelake)
Threads: 1 default, 0 interactive, 1 GC (on 40 virtual cores)
Environment:
  LD_LIBRARY_PATH = /opt/ohpc/pub/apps/intel2022/itac/2020.3.036/intel64/slib:/opt/ohpc/pub/apps/intel2022/compilers_and_libraries_2020.4.304/linux/compiler/lib/intel64_lin:/opt/ohpc/pub/apps/intel2022/compilers_and_libraries_2020.4.304/linux/mpi/intel64/libfabric/lib:/opt/ohpc/pub/apps/intel2022/compilers_and_libraries_2020.4.304/linux/mpi/intel64/lib/release:/opt/ohpc/pub/apps/intel2022/compilers_and_libraries_2020.4.304/linux/mpi/intel64/lib:/opt/ohpc/pub/apps/intel2022/compilers_and_libraries_2020.4.304/linux/ipp/lib/intel64:/opt/ohpc/pub/apps/intel2022/compilers_and_libraries_2020.4.304/linux/mkl/lib/intel64_lin:/opt/ohpc/pub/apps/intel2022/compilers_and_libraries_2020.4.304/linux/tbb/lib/intel64/gcc4.8:/opt/ohpc/pub/apps/intel2022/debugger_2020/python/intel64/lib:/opt/ohpc/pub/apps/intel2022/debugger_2020/libipt/intel64/lib:/opt/ohpc/pub/apps/intel2022/compilers_and_libraries_2020.4.304/linux/daal/lib/intel64_lin:/opt/ohpc/pub/apps/intel2022/compilers_and_libraries_2020.4.304/linux/daal/../tbb/lib/intel64_lin/gcc4.4:/opt/ohpc/pub/apps/intel2022/compilers_and_libraries_2020.4.304/linux/daal/../tbb/lib/intel64_lin/gcc4.8:/opt/ohpc/pub/compiler/gcc/8.3.0/lib64:/opt/ohpc/pub/apps/tensorflow/TensorRT-7.2.3.4/targets/x86_64-linux-gnu/lib
  JULIA_PKG_SERVER = https://mirrors.sjtug.sjtu.edu.cn/julia/

运行

  • 显示Julia已安装的所有包,
1
2
3
4
julia> using Pkg; Pkg.status()
Status `C:\Users\lenovo\.julia\environments\v1.9\Project.toml`
  [052768ef] CUDA v4.4.0
  [acf6eb54] DFTK v0.6.9
  • 代理,修改startup.jl
1
2
ENV["HTTP_PROXY"] = "socks5://127.0.0.1:7890"
ENV["HTTPS_PROXY"] = "socks5://127.0.0.1:7890"
  • 安装与删除包,
1
2
3
using Pkg
Pkg.add()
Pkg.rm()
1
2
3
4
using Pkg; Pkg.add(PackageSpec(url="https://github.com/WMD-group/CarrierCapture.jl"))
Pkg.add("Plots"); Pkg.add("LaTeXStrings");Pkg.add("DataFrames")
# import Pkg; Pkg.precompile()
using CarrierCapture
1
2
3
4
using Pkg; Pkg.add("PyCall")
ENV["PYTHON"]="C:/Users/lenovo/anaconda3/python.exe"
Pkg.build("PyCall")
using PyCall

Notepad++

Notepad++调用

在Notepad++中运行-运行,输入以下代码,

1
cmd /k julia "$(FULL_CURRENT_PATH)" & PAUSE & EXIT

Notepad++语法高亮

下载Julia_Notepad++.xml,放置于~\npp.7.5.5\plugins\APIs,然后在语言-自定义语言格式中导入。

Notepad++关联.jl文件

新建.reg,加入,

1
2
3
4
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\.jl] 
[HKEY_CURRENT_USER\Software\Classes\.jl\shell]
[HKEY_CURRENT_USER\Software\Classes\.jl\shell\open]

然后在Win10设置中搜索选择文件类型和每个应用打开的协议,将jl文件默认程序指定为Notepad++即可。

文档


  1. Building Julia from sources on Linux ↩︎