Hi everyone,
I’m currently working on a program and need some help for better performance. As I switched from MATLAB to Julia, I don’t know if I am writting in a good way. I tried to write it similarly to MATLAB’s fashion, but it seems to take longer and I don’t know if that is due to some Atom / Julia Pro (yes, I don’t know why Atom with Juno seems to work way slower than the standard Julia REPL interface) issue as I run my code or if this is matter of poor writing. In general, the code is as follows:
1 - example.jl declares variables (global in Main), which are Dicts{String,Any} because there are Int64 and Float64 arrays associated to the keys;
2 - functions.jl contain a module with several functions inside it using Base.include() to add each function. I also call some packages from within the module (Don’t know if that’s the best practice);
3 - Program_Drive.jl that loads example.jl variables (Dicts) into Main, import the module functions and run a specific function from within that module. As the user may specify which function need to be loaded, the function getfiled() is used.
Here are some main important files in the code:
example.jl
df = Dict{String,Any}(some Float64 arrays, some Int64 arrays);
elem = Dict{String,Any}(some Float64 arrays, some Int64 arrays);
inf = Dict{String,Any}(some Float64 arrays, some Int64 arrays);
functions.jl
module functions
using LinearAlgebra, Plots , Distributions, XLSX
include("function1.jl");
include("function1.jl");
include("function1.jl");
include("function1.jl");
include("function1.jl");
end
Program_Drive.jl
cd("path/to/my/program/files");
include("functions.jl");
import .functions;
include("example.jl"); # loads the variables into Main
method = "function1";
u = Array{Float64,1};
cr = "function3";
U = getfield(Main.functions,Symbol(method))(df,elem,inf,u,cr,); # passes global variables from # Main as arguments to the function1.
I know avoiding global variables is a good practice, but I only use it to load the information from example.jl which is later used as arguments for the functions. Writing codes in MATLAB is all about functions and scripts mostly, and quite often declaring type of variables won’t affect too much this kind of code I’m doing. In addition, availability of packages/functions inside modules is a little confusing me to sometimes.
I would really appreciate if anybody could help me out with this issue. I’m definitely not deep into Julia, but I want to be. Thank you all in advance.