var documenterSearchIndex = {"docs": [{"location":"getting_started_with_julia/#Getting-started","page":"Getting started","title":"Getting started","text":"","category":"section"},{"location":"getting_started_with_julia/#Introduction","page":"Getting started","title":"Introduction","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"The programming of this course will be done using the Julia programming language. Thus, we start by explaining how to get up and running with Julia. After studying this page, you will be able to:","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Use the Julia REPL,\nRun serial and parallel code,\nInstall and manage Julia packages.","category":"page"},{"location":"getting_started_with_julia/#Why-Julia?","page":"Getting started","title":"Why Julia?","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Courses related with high-performance computing (HPC) often use languages such as C, C++, or Fortran. We use Julia instead to make the course accessible to a wider set of students, including the ones that have no experience with C/C++ or Fortran, but are willing to learn parallel programming. Julia is a relatively new programming language specifically designed for scientific computing. It combines a high-level syntax close to interpreted languages like Python with the performance of compiled languages like C, C++, or Fortran. Thus, Julia will allow us to write efficient parallel algorithms with a syntax that is convenient in a teaching setting. In addition, Julia provides easy access to different programming models to write distributed algorithms, which will be useful to learn and experiment with them.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"tip: Tip\nYou can run the code in this link to learn how Julia compares to other languages (C and Python) in terms of performance.","category":"page"},{"location":"getting_started_with_julia/#Installing-Julia","page":"Getting started","title":"Installing Julia","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"This is a tutorial-like page. Follow these steps before you continue reading the document.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Download and install Julia from julialang.org;\nFollow the specific instructions for your operating system: Windows, MacOS, or Linux\nDownload and install VSCode and its Julia extension;","category":"page"},{"location":"getting_started_with_julia/#The-Julia-REPL","page":"Getting started","title":"The Julia REPL","text":"","category":"section"},{"location":"getting_started_with_julia/#Starting-Julia","page":"Getting started","title":"Starting Julia","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"There are several ways of opening Julia depending on your operating system and your IDE, but it is usually as simple as launching the Julia app. With VSCode, open a folder (File > Open Folder). Then, press Ctrl+Shift+P to open the command bar, and execute Julia: Start REPL. If this does not work, make sure you have the Julia extension for VSCode installed. Independently of the method you use, opening Julia results in a window with some text ending with:","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia>","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"You have just opened the Julia read-evaluate-print loop, or simply the Julia REPL. Congrats! You will spend most of time using the REPL, when working in Julia. The REPL is a console waiting for user input. Just as in other consoles, the string of text right before the input area (julia> in the case) is called the command prompt or simply the prompt.","category":"page"},{"location":"getting_started_with_julia/#Basic-usage","page":"Getting started","title":"Basic usage","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"The usage of the REPL is as follows:","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"You write some input\npress enter\nyou get the output","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"For instance, try this","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> 1 + 1","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"A \"Hello world\" example looks like this in Julia","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> println(\"Hello, world!\")","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Try to run it in the REPL.","category":"page"},{"location":"getting_started_with_julia/#Help-mode","page":"Getting started","title":"Help mode","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Curious about what the function println does? Enter into help mode to look into the documentation. This is done by typing a question mark (?) into the input field:","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> ?","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"After typing ?, the command prompt changes to help?>. It means we are in help mode. Now, we can type a function name to see its documentation.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"help?> println","category":"page"},{"location":"getting_started_with_julia/#Package-and-shell-modes","page":"Getting started","title":"Package and shell modes","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"The REPL comes with two more modes, namely package and shell modes. To enter package mode type","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> ]","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Package mode is used to install and manage packages. We are going to discuss the package mode in greater detail later. To return back to normal mode press the backspace key several times.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"To enter shell mode type semicolon (;)","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> ;","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"The prompt should have changed to shell> indicating that we are in shell mode. Now you can type commands that you would normally do on your system command line. For instance,","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"shell> ls","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"will display the contents of the current folder in Mac or Linux. Using shell mode in Windows is not straightforward, and thus not recommended for beginners.","category":"page"},{"location":"getting_started_with_julia/#Running-Julia-code","page":"Getting started","title":"Running Julia code","text":"","category":"section"},{"location":"getting_started_with_julia/#Running-more-complex-code","page":"Getting started","title":"Running more complex code","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Real-world Julia programs are not typed in the REPL in practice. They are written in one or more files and included in the REPL. To try this, create a new file called hello.jl, write the code of the \"Hello world\" example above, and save it. If you are using VSCode, you can create the file using File > New File > Julia File. Once the file is saved with the name hello.jl, execute it as follows","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> include(\"hello.jl\")","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"warning: Warning\nMake sure that the file \"hello.jl\" is located in the current working directory of your Julia session. You can query the current directory with function pwd(). You can change to another directory with function cd() if needed. Also, make sure that the file extension is .jl.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"The recommended way of running Julia code is using the REPL as we did. But it is also possible to run code directly from the system command line. To this end, open a terminal and call Julia followed by the path to the file containing the code you want to execute.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"$ julia hello.jl","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"The previous line assumes that you have Julia properly installed in the system and that it's usable from the terminal. In UNIX systems (Linux and Mac), the Julia binary needs to be in one of the directories listed in the PATH environment variable. To check that Julia is properly installed, you can use","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"$ julia --version","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"If this runs without error and you see a version number, you are good to go!","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"You can also run julia code from the terminal using the -e flag:","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"$ julia -e 'println(\"Hello, world!\")'","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"note: Note\nIn this tutorial, when a code snipped starts with $, it should be run in the terminal. Otherwise, the code is to be run in the Julia REPL.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"tip: Tip\nAvoid calling Julia code from the terminal, use the Julia REPL instead! Each time you call Julia from the terminal, you start a fresh Julia session and Julia will need to compile your code from scratch. This can be time consuming for large projects. In contrast, if you execute code in the REPL, Julia will compile code incrementally, which is much faster. Running code in a cluster (like in DAS-5 for the Julia assignment) is among the few situations you need to run Julia code from the terminal. Visit this link (Julia workflow tips) from the official Julia documentation for further information about how to develop Julia code effectivelly.","category":"page"},{"location":"getting_started_with_julia/#Running-parallel-code","page":"Getting started","title":"Running parallel code","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Since we are in a parallel computing course, let's run a parallel \"Hello world\" example in Julia. Open a Julia REPL and write","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> using Distributed\njulia> @everywhere println(\"Hello, world! I am proc $(myid()) from $(nprocs())\")","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Here, we are using the Distributed package, which is part of the Julia standard library that provides distributed memory parallel support. The code prints the process id and the number of processes in the current Julia session.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"You will probably only see output from 1 process. We need to add more processes to run the example in parallel. This is done with the addprocs function.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> addprocs(3)","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"We have added 3 new processes. Plus the old one, we have 4 processes. Run the code again.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> @everywhere println(\"Hello, world! I am proc $(myid()) from $(nprocs())\")","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Now, you should see output from 4 processes.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"It is possible to specify the number of processes when starting Julia from the terminal with the -p argument (useful, e.g., when running in a cluster). If you launch Julia from the terminal as","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"$ julia -p 3","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"and then run","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> @everywhere println(\"Hello, world! I am proc $(myid()) from $(nprocs())\")","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"You should get output from 4 processes as before.","category":"page"},{"location":"getting_started_with_julia/#Installing-packages","page":"Getting started","title":"Installing packages","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"One of the most useful features of Julia is its package manager. It allows one to install Julia packages in a straightforward and platform independent way. To illustrate this, let us consider the following parallel \"Hello world\" example. This example uses the Message Passing Interface (MPI). We will learn more about MPI later in the course.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Copy the following block of code into a new file named \"hello_mpi.jl\"","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"# file hello_mpi.jl\nusing MPI\nMPI.Init()\ncomm = MPI.COMM_WORLD\nrank = MPI.Comm_rank(comm)\nnranks = MPI.Comm_size(comm)\nprintln(\"Hello world, I am rank $rank of $nranks\")","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"As you can see from this example, one can access MPI from Julia in a clean way, without type annotations and other complexities of C/C++ code.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Now, run the file from the REPL","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> include(\"hello_mpi.jl\")","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"It probably didn't work, right? Read the error message and note that the MPI package needs to be installed to run this code.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"To install a package, we need to enter package mode. Remember that we entered into help mode by typing ?. Package mode is activated by typing ] : ","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> ]","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"At this point, the prompt should have changed to (@v1.10) pkg> indicating that we are in package mode. The text between the parentheses indicates which is the active project, i.e., where packages are going to be installed. In this case, we are working with the global project associated with our Julia installation (which is Julia 1.10 in this example, but it can be another version in your case).","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"To install the MPI package, type","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(@v1.10) pkg> add MPI","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Congrats, you have installed MPI!","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"note: Note\nMany Julia package names end with .jl. This is just a way of signaling that a package is written in Julia. When using such packages, the .jl needs to be omitted. In this case, we have installed the MPI.jl package even though we have only typed MPI in the REPL.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"note: Note\nThe package you have installed is the Julia interface to MPI, called MPI.jl. Note that it is not a MPI library by itself. It is just a thin wrapper between MPI and Julia. To use this interface, you need an actual MPI library installed in your system such as OpenMPI or MPICH. Julia downloads and installs a MPI library for you, but it is also possible to use a MPI library already available in your system. This is useful, e.g., when running on HPC clusters. See the documentation of MPI.jl for further details.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"To check that the package was installed properly, exit package mode by pressing the backspace key several times, and run it again","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> include(\"hello_mpi.jl\")","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Now, it should work, but you probably get output from a single MPI rank only.","category":"page"},{"location":"getting_started_with_julia/#Running-MPI-code","page":"Getting started","title":"Running MPI code","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"To run MPI applications in parallel, you need a launcher like mpiexec. MPI codes written in Julia are not an exception to this rule. From the system terminal, you can run","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"$ mpiexec -np 4 julia hello_mpi.jl","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"But it will probably not work since the version of mpiexec needs to match with the MPI version we are using from Julia. Don't worry if you could not make it work! A more elegant way to run MPI code is from the Julia REPL directly, by using these commands:","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> using MPI\njulia> run(`$(mpiexec()) -np 4 julia hello_mpi.jl`)","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Now, you should see output from 4 ranks.","category":"page"},{"location":"getting_started_with_julia/#Package-manager","page":"Getting started","title":"Package manager","text":"","category":"section"},{"location":"getting_started_with_julia/#Installing-packages-locally","page":"Getting started","title":"Installing packages locally","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"We have installed the MPI package globally and it will be available in all Julia sessions. However, in some situations, we want to work with different versions of the same package or to install packages in an isolated way to avoid potential conflicts with other packages. This can be done by using local projects.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"A project is simply a folder in your file system. To use a particular folder as your project, you need to activate it. This is done by entering package mode and using the activate command followed by the path to the folder you want to activate.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(@v1.10) pkg> activate .","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"The previous command will activate the current working directory. Note that the dot . is indeed the path to the current folder.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"The prompt has changed to (lessons) pkg> indicating that we are in the project within the lessons folder. The particular folder name can be different in your case.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"tip: Tip\nYou can activate a project directly when opening Julia from the terminal using the --project flag. The command $ julia --project=. will open Julia and activate a project in the current directory. You can also achieve the same effect by setting the environment variable JULIA_PROJECT with the path of the folder you want to activate.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"note: Note\nThe active project folder and the current working directory are two independent concepts! For instance, (@v1.10) pkg> activate folderB and then julia> cd(\"folderA\"), will activate the project in folderB and change the current working directory to folderA.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"At this point all package-related operations will be local to the new project. For instance, install the DataFrames package.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(lessons) pkg> add DataFrames","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Use the package to check that it is installed","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> using DataFrames\njulia> DataFrame(a=[1,2],b=[3,4])","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Now, we can return to the global project to check that DataFrames has not been installed there. To return to the global environment, use activate without a folder name.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(lessons) pkg> activate","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"The prompt is again (@v1.10) pkg>","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Now, try to use DataFrames.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> using DataFrames\njulia> DataFrame(a=[1,2],b=[3,4])","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"You should get an error or a warning unless you already had DataFrames installed globally.","category":"page"},{"location":"getting_started_with_julia/#Project-and-Manifest-files","page":"Getting started","title":"Project and Manifest files","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"The information about a project is stored in two files Project.toml and Manifest.toml.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Project.toml contains the packages explicitly installed (the direct dependencies)\nManifest.toml contains direct and indirect dependencies along with the concrete version of each package.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"In other words, Project.toml contains the packages relevant for the user, whereas Manifest.toml is the detailed snapshot of all dependencies. The Manifest.toml can be used to reproduce the same environment in another machine.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"You can see the path to the current Project.toml file by using the status operator (or st in its short form) while in package mode","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(@v1.10) pkg> status","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"The information about the Manifest.toml can be inspected by passing the -m flag.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(@v1.10) pkg> status -m","category":"page"},{"location":"getting_started_with_julia/#Installing-packages-from-a-project-file","page":"Getting started","title":"Installing packages from a project file","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Project files can be used to install lists of packages defined by others. E.g., to install all the dependencies of a Julia application.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Assume that a colleague has sent to you a Project.toml file with this content:","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"[deps]\nBenchmarkTools = \"6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf\"\nDataFrames = \"a93c6f00-e57d-5684-b7b6-d8193f3e46c0\"\nMPI = \"da04e1cc-30fd-572f-bb4f-1f8673147195\"","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Copy the contents of previous code block into a file called Project.toml and place it in an empty folder named newproject. It is important that the file is named Project.toml. You can create a new folder from the REPL with","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> mkdir(\"newproject\")","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"To install all the packages registered in this file you need to activate the folder containing your Project.toml file","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(@v1.10) pkg> activate newproject","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"and then instantiating it","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(newproject) pkg> instantiate","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"The instantiate command will download and install all listed packages and their dependencies in just one click.","category":"page"},{"location":"getting_started_with_julia/#Getting-help-in-package-mode","page":"Getting started","title":"Getting help in package mode","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"You can get help about a particular package operator by writing help in front of it","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(@v1.10) pkg> help activate","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"You can get an overview of all package commands by typing help alone","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(@v1.10) pkg> help","category":"page"},{"location":"getting_started_with_julia/#Package-operations-in-Julia-code","page":"Getting started","title":"Package operations in Julia code","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"In some situations it is required to use package commands in Julia code, e.g., to automatize installation and deployment of Julia applications. This can be done using the Pkg package. For instance","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"julia> using Pkg\njulia> Pkg.status()","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"is equivalent to calling status in package mode.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(@v1.10) pkg> status","category":"page"},{"location":"getting_started_with_julia/#Creating-you-own-package","page":"Getting started","title":"Creating you own package","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"In many situations, it is useful to create your own package, for instance, when working with a large code base, when you want to reduce compilation latency using Revise.jl, or if you want to eventually register your package and share it with others.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"The simplest way of generating a package (called MyPackage) is as follows. Open Julia, go to package mode, and type","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(@v1.10) pkg> generate MyPackage","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"This will crate a minimal package consisting of a new folder MyPackage with two files:","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"MyPackage/Project.toml: Project file defining the direct dependencies of your package.\nMyPackage/src/MyPackage.jl: Main source file of your package. You can split your code in several files if needed, and include them in the package main file using function include.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"tip: Tip\nThis approach only generates a very minimal package. To create a more sophisticated package skeleton (including unit testing, code coverage, readme file, licence, etc.) use PkgTemplates.jl or BestieTemplate.jl. The later one is developed in Amsterdam at the Netherlands eScience Center.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"You can add dependencies to the package by activating the MyPackage folder in package mode and adding new dependencies as always:","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(@v1.10) pkg> activate MyPackage\n(MyPackage) pkg> add MPI","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"This will add MPI to your package dependencies.","category":"page"},{"location":"getting_started_with_julia/#Using-your-own-package","page":"Getting started","title":"Using your own package","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"To use your package you first need to add it to a package environment of your choice. This is done by changing to package mode and typing develop followed by the path to the folder containing the package. For instance:","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"(@v1.10) pkg> develop MyPackage","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"note: Note\nYou do not need to \"develop\" your package if you activated the package folder MyPackage.","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Now, we can go back to standard Julia mode and use it as any other package:","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"using MyPackage\nMyPackage.greet()","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Here, we just called the example function defined in MyPackage/src/MyPackage.jl.","category":"page"},{"location":"getting_started_with_julia/#Conclusion","page":"Getting started","title":"Conclusion","text":"","category":"section"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"We have learned the basics of how to work with Julia, including how to run serial and parallel code, and how to manage, create, and use Julia packages. This knowledge will allow you to follow the course effectively! If you want to further dig into the topics we have covered here, you can take a look at the following links:","category":"page"},{"location":"getting_started_with_julia/","page":"Getting started","title":"Getting started","text":"Julia Manual\nPackage manager","category":"page"},{"location":"tsp/","page":"Traveling salesperson problem","title":"Traveling salesperson problem","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/tsp.ipynb\"","category":"page"},{"location":"tsp/","page":"Traveling salesperson problem","title":"Traveling salesperson problem","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"tsp/","page":"Traveling salesperson problem","title":"Traveling salesperson problem","text":"\n","category":"page"},{"location":"mpi_collectives/","page":"MPI (collectives)","title":"MPI (collectives)","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/mpi_collectives.ipynb\"","category":"page"},{"location":"mpi_collectives/","page":"MPI (collectives)","title":"MPI (collectives)","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"mpi_collectives/","page":"MPI (collectives)","title":"MPI (collectives)","text":"\n","category":"page"},{"location":"jacobi_2D/","page":"-","title":"-","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/jacobi_2D.ipynb\"","category":"page"},{"location":"jacobi_2D/","page":"-","title":"-","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"jacobi_2D/","page":"-","title":"-","text":"\n","category":"page"},{"location":"julia_async/","page":"Asynchronous programming in Julia","title":"Asynchronous programming in Julia","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/julia_async.ipynb\"","category":"page"},{"location":"julia_async/","page":"Asynchronous programming in Julia","title":"Asynchronous programming in Julia","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"julia_async/","page":"Asynchronous programming in Julia","title":"Asynchronous programming in Julia","text":"\n","category":"page"},{"location":"solutions/","page":"-","title":"-","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/solutions.ipynb\"","category":"page"},{"location":"solutions/","page":"-","title":"-","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"solutions/","page":"-","title":"-","text":"\n","category":"page"},{"location":"pdes/","page":"-","title":"-","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/pdes.ipynb\"","category":"page"},{"location":"pdes/","page":"-","title":"-","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"pdes/","page":"-","title":"-","text":"\n","category":"page"},{"location":"LEQ/","page":"Gaussian elimination","title":"Gaussian elimination","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/LEQ.ipynb\"","category":"page"},{"location":"LEQ/","page":"Gaussian elimination","title":"Gaussian elimination","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"LEQ/","page":"Gaussian elimination","title":"Gaussian elimination","text":"\n","category":"page"},{"location":"julia_distributed/","page":"Distributed computing in Julia","title":"Distributed computing in Julia","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/julia_distributed.ipynb\"","category":"page"},{"location":"julia_distributed/","page":"Distributed computing in Julia","title":"Distributed computing in Julia","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"julia_distributed/","page":"Distributed computing in Julia","title":"Distributed computing in Julia","text":"\n","category":"page"},{"location":"julia_jacobi/","page":"-","title":"-","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/julia_jacobi.ipynb\"","category":"page"},{"location":"julia_jacobi/","page":"-","title":"-","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"julia_jacobi/","page":"-","title":"-","text":"\n","category":"page"},{"location":"julia_tutorial/","page":"-","title":"-","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/julia_tutorial.ipynb\"","category":"page"},{"location":"julia_tutorial/","page":"-","title":"-","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"julia_tutorial/","page":"-","title":"-","text":"\n","category":"page"},{"location":"mpi_tutorial/","page":"-","title":"-","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/mpi_tutorial.ipynb\"","category":"page"},{"location":"mpi_tutorial/","page":"-","title":"-","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"mpi_tutorial/","page":"-","title":"-","text":"\n","category":"page"},{"location":"notebook-hello/","page":"-","title":"-","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/notebook-hello.ipynb\"","category":"page"},{"location":"notebook-hello/","page":"-","title":"-","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"notebook-hello/","page":"-","title":"-","text":"\n","category":"page"},{"location":"julia_intro/","page":"-","title":"-","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/julia_intro.ipynb\"","category":"page"},{"location":"julia_intro/","page":"-","title":"-","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"julia_intro/","page":"-","title":"-","text":"\n","category":"page"},{"location":"jacobi_method/","page":"Jacobi method","title":"Jacobi method","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/jacobi_method.ipynb\"","category":"page"},{"location":"jacobi_method/","page":"Jacobi method","title":"Jacobi method","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"jacobi_method/","page":"Jacobi method","title":"Jacobi method","text":"\n","category":"page"},{"location":"solutions_for_all_notebooks/#Solutions","page":"Solutions","title":"Solutions","text":"","category":"section"},{"location":"solutions_for_all_notebooks/#Julia-Basics","page":"Solutions","title":"Julia Basics","text":"","category":"section"},{"location":"solutions_for_all_notebooks/#Exercise-1","page":"Solutions","title":"Exercise 1","text":"","category":"section"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"function ex1(a)\n j = 1\n m = a[j]\n for (i,ai) in enumerate(a)\n if m < ai\n m = ai\n j = i\n end\n end\n (m,j)\nend","category":"page"},{"location":"solutions_for_all_notebooks/#Exercise-2","page":"Solutions","title":"Exercise 2","text":"","category":"section"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"ex2(f,g) = x -> f(x) + g(x)","category":"page"},{"location":"solutions_for_all_notebooks/#Exercise-3","page":"Solutions","title":"Exercise 3","text":"","category":"section"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"using GLMakie\nmax_iters = 100\nn = 1000\nx = LinRange(-1.7,0.7,n)\ny = LinRange(-1.2,1.2,n)\nheatmap(x,y,(i,j)->mandel(i,j,max_iters))","category":"page"},{"location":"solutions_for_all_notebooks/#Asynchronous-programming-in-Julia","page":"Solutions","title":"Asynchronous programming in Julia","text":"","category":"section"},{"location":"solutions_for_all_notebooks/#Distributed-computing-in-Julia","page":"Solutions","title":"Distributed computing in Julia","text":"","category":"section"},{"location":"solutions_for_all_notebooks/#Exercise-1-2","page":"Solutions","title":"Exercise 1","text":"","category":"section"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"f = () -> Channel{Int}(1)\nchnls = [ RemoteChannel(f,w) for w in workers() ]\n@sync for (iw,w) in enumerate(workers())\n @spawnat w begin\n chnl_snd = chnls[iw]\n if w == 2\n chnl_rcv = chnls[end]\n msg = 2\n println(\"msg = $msg\")\n put!(chnl_snd,msg)\n msg = take!(chnl_rcv)\n println(\"msg = $msg\")\n else\n chnl_rcv = chnls[iw-1]\n msg = take!(chnl_rcv)\n msg += 1\n println(\"msg = $msg\")\n put!(chnl_snd,msg)\n end\n end\nend","category":"page"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"This is another possible solution.","category":"page"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"@everywhere function work(msg)\n println(\"msg = $msg\")\n if myid() != nprocs()\n next = myid() + 1\n @fetchfrom next work(msg+1)\n else\n @fetchfrom 2 println(\"msg = $msg\")\n end\nend\nmsg = 2\n@fetchfrom 2 work(msg)","category":"page"},{"location":"solutions_for_all_notebooks/#Matrix-matrix-multiplication","page":"Solutions","title":"Matrix-matrix multiplication","text":"","category":"section"},{"location":"solutions_for_all_notebooks/#Exercise-1-3","page":"Solutions","title":"Exercise 1","text":"","category":"section"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"function matmul_dist_3!(C,A,B)\n m = size(C,1)\n n = size(C,2)\n l = size(A,2)\n @assert size(A,1) == m\n @assert size(B,2) == n\n @assert size(B,1) == l\n @assert mod(m,nworkers()) == 0\n nrows_w = div(m,nworkers())\n @sync for (iw,w) in enumerate(workers())\n lb = 1 + (iw-1)*nrows_w\n ub = iw*nrows_w\n A_w = A[lb:ub,:]\n ftr = @spawnat w begin\n C_w = similar(A_w)\n matmul_seq!(C_w,A_w,B)\n C_w\n end\n @async C[lb:ub,:] = fetch(ftr)\n end\n C\nend\n\n@everywhere function matmul_seq!(C,A,B)\n m = size(C,1)\n n = size(C,2)\n l = size(A,2)\n @assert size(A,1) == m\n @assert size(B,2) == n\n @assert size(B,1) == l\n z = zero(eltype(C))\n for j in 1:n\n for i in 1:m\n Cij = z\n for k in 1:l\n @inbounds Cij = Cij + A[i,k]*B[k,j]\n end\n C[i,j] = Cij\n end\n end\n C\nend","category":"page"},{"location":"solutions_for_all_notebooks/#MPI-(Point-to-point)","page":"Solutions","title":"MPI (Point-to-point)","text":"","category":"section"},{"location":"solutions_for_all_notebooks/#Exercise-1-4","page":"Solutions","title":"Exercise 1","text":"","category":"section"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"function matmul_mpi_3!(C,A,B)\n comm = MPI.COMM_WORLD\n rank = MPI.Comm_rank(comm)\n P = MPI.Comm_size(comm)\n if rank == 0\n N = size(A,1)\n myB = B\n for dest in 1:(P-1)\n MPI.Send(B,comm;dest)\n end\n else\n source = 0\n status = MPI.Probe(comm,MPI.Status;source)\n count = MPI.Get_count(status,eltype(B))\n N = Int(sqrt(count))\n myB = zeros(N,N)\n MPI.Recv!(myB,comm;source)\n end\n L = div(N,P)\n myA = zeros(L,N)\n if rank == 0\n lb = L*rank+1\n ub = L*(rank+1)\n myA[:,:] = view(A,lb:ub,:)\n for dest in 1:(P-1)\n lb = L*dest+1\n ub = L*(dest+1)\n MPI.Send(view(A,lb:ub,:),comm;dest)\n end\n else\n source = 0\n MPI.Recv!(myA,comm;source)\n end\n myC = myA*myB\n if rank == 0\n lb = L*rank+1\n ub = L*(rank+1)\n C[lb:ub,:] = myC\n for source in 1:(P-1)\n lb = L*source+1\n ub = L*(source+1)\n MPI.Recv!(view(C,lb:ub,:),comm;source)\n end\n else\n dest = 0\n MPI.Send(myC,comm;dest)\n end\n C\nend","category":"page"},{"location":"solutions_for_all_notebooks/#Exercise-2-2","page":"Solutions","title":"Exercise 2","text":"","category":"section"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"using MPI\nMPI.Init()\ncomm = MPI.COMM_WORLD\nrank = MPI.Comm_rank(comm)\nnranks = MPI.Comm_size(comm)\nbuffer = Ref(0)\nif rank == 0\n msg = 2\n buffer[] = msg\n println(\"msg = $(buffer[])\")\n MPI.Send(buffer,comm;dest=rank+1,tag=0)\n MPI.Recv!(buffer,comm;source=nranks-1,tag=0)\n println(\"msg = $(buffer[])\")\nelse\n dest = if (rank != nranks-1)\n rank+1\n else\n 0\n end\n MPI.Recv!(buffer,comm;source=rank-1,tag=0)\n buffer[] += 1\n println(\"msg = $(buffer[])\")\n MPI.Send(buffer,comm;dest,tag=0)\nend","category":"page"},{"location":"solutions_for_all_notebooks/#MPI-(collectives)","page":"Solutions","title":"MPI (collectives)","text":"","category":"section"},{"location":"solutions_for_all_notebooks/#Exercise-1-5","page":"Solutions","title":"Exercise 1","text":"","category":"section"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"function matmul_mpi_3!(C,A,B)\n comm = MPI.COMM_WORLD\n rank = MPI.Comm_rank(comm)\n P = MPI.Comm_size(comm)\n root = 0\n if rank == root\n N = size(A,1)\n Nref = Ref(N)\n else\n Nref = Ref(0)\n end\n MPI.Bcast!(Nref,comm;root)\n N = Nref[]\n if rank == root\n myB = B\n else\n myB = zeros(N,N)\n end\n MPI.Bcast!(myB,comm;root)\n L = div(N,P)\n # Tricky part\n # Julia works \"col major\"\n myAt = zeros(N,L)\n At = collect(transpose(A))\n MPI.Scatter!(At,myAt,comm;root)\n myCt = transpose(myB)*myAt\n Ct = similar(C)\n MPI.Gather!(myCt,Ct,comm;root)\n C .= transpose(Ct)\n C\nend","category":"page"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"This other solution uses a column partition instead of a row partition. It is more natural to work with column partitions in Julia if possible since matrices are in \"col major\" format. Note that we do not need all the auxiliary transposes anymore.","category":"page"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"function matmul_mpi_3!(C,A,B)\n comm = MPI.COMM_WORLD\n rank = MPI.Comm_rank(comm)\n P = MPI.Comm_size(comm)\n root = 0\n if rank == root\n N = size(A,1)\n Nref = Ref(N)\n else\n Nref = Ref(0)\n end\n MPI.Bcast!(Nref,comm;root)\n N = Nref[]\n if rank == root\n myA = A\n else\n myA = zeros(N,N)\n end\n MPI.Bcast!(myA,comm;root)\n L = div(N,P)\n myB = zeros(N,L)\n MPI.Scatter!(B,myB,comm;root)\n myC = myA*myB\n MPI.Gather!(myC,C,comm;root)\n C\nend","category":"page"},{"location":"solutions_for_all_notebooks/#Jacobi-method","page":"Solutions","title":"Jacobi method","text":"","category":"section"},{"location":"solutions_for_all_notebooks/#Exercise-1-6","page":"Solutions","title":"Exercise 1","text":"","category":"section"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"function jacobi_mpi(n,niters)\n u, u_new = init(n,comm)\n load = length(u)-2\n rank = MPI.Comm_rank(comm)\n nranks = MPI.Comm_size(comm)\n nreqs = 2*((rank != 0) + (rank != (nranks-1)))\n reqs = MPI.MultiRequest(nreqs)\n for t in 1:niters\n ireq = 0\n if rank != 0\n neig_rank = rank-1\n u_snd = view(u,2:2)\n u_rcv = view(u,1:1)\n dest = neig_rank\n source = neig_rank\n ireq += 1\n MPI.Isend(u_snd,comm,reqs[ireq];dest)\n ireq += 1\n MPI.Irecv!(u_rcv,comm,reqs[ireq];source)\n end\n if rank != (nranks-1)\n neig_rank = rank+1\n u_snd = view(u,(load+1):(load+1))\n u_rcv = view(u,(load+2):(load+2))\n dest = neig_rank\n source = neig_rank\n ireq += 1\n MPI.Isend(u_snd,comm,reqs[ireq];dest)\n ireq += 1\n MPI.Irecv!(u_rcv,comm,reqs[ireq];source)\n end\n # Upload interior cells\n for i in 3:load\n u_new[i] = 0.5*(u[i-1]+u[i+1])\n end\n # Wait for the communications to finish\n MPI.Waitall(reqs)\n # Update boundaries\n for i in (2,load+1)\n u_new[i] = 0.5*(u[i-1]+u[i+1])\n end\n u, u_new = u_new, u\n end\n return u\nend","category":"page"},{"location":"solutions_for_all_notebooks/#Exercise-2-3","page":"Solutions","title":"Exercise 2","text":"","category":"section"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"function jacobi_mpi(n,niters,tol,comm) # new tol arg\n u, u_new = init(n,comm)\n load = length(u)-2\n rank = MPI.Comm_rank(comm)\n nranks = MPI.Comm_size(comm)\n nreqs = 2*((rank != 0) + (rank != (nranks-1)))\n reqs = MPI.MultiRequest(nreqs)\n for t in 1:niters\n ireq = 0\n if rank != 0\n neig_rank = rank-1\n u_snd = view(u,2:2)\n u_rcv = view(u,1:1)\n dest = neig_rank\n source = neig_rank\n ireq += 1\n MPI.Isend(u_snd,comm,reqs[ireq];dest)\n ireq += 1\n MPI.Irecv!(u_rcv,comm,reqs[ireq];source)\n end\n if rank != (nranks-1)\n neig_rank = rank+1\n u_snd = view(u,(load+1):(load+1))\n u_rcv = view(u,(load+2):(load+2))\n dest = neig_rank\n source = neig_rank\n ireq += 1\n MPI.Isend(u_snd,comm,reqs[ireq];dest)\n ireq += 1\n MPI.Irecv!(u_rcv,comm,reqs[ireq];source)\n end\n MPI.Waitall(reqs)\n # Compute the max diff in the current\n # rank while doing the local update\n mydiff = 0.0\n for i in 2:load+1\n u_new[i] = 0.5*(u[i-1]+u[i+1])\n diff_i = abs(u_new[i] - u[i])\n mydiff = max(mydiff,diff_i)\n end\n # Now we need to find the global diff\n diff_ref = Ref(mydiff)\n MPI.Allreduce!(diff_ref,max,comm)\n diff = diff_ref[]\n # If global diff below tol, stop!\n if diff < tol\n return u_new\n end\n u, u_new = u_new, u\n end\n return u\nend","category":"page"},{"location":"solutions_for_all_notebooks/#All-pairs-of-shortest-paths","page":"Solutions","title":"All pairs of shortest paths","text":"","category":"section"},{"location":"solutions_for_all_notebooks/#Exercise-1-7","page":"Solutions","title":"Exercise 1","text":"","category":"section"},{"location":"solutions_for_all_notebooks/","page":"Solutions","title":"Solutions","text":"function floyd_iterations!(myC,comm)\n L = size(myC,1)\n N = size(myC,2)\n rank = MPI.Comm_rank(comm)\n P = MPI.Comm_size(comm)\n lb = L*rank+1\n ub = L*(rank+1)\n C_k = similar(myC,N)\n for k in 1:N\n if (lb<=k) && (k<=ub)\n # If I have the row, fill in the buffer\n myk = (k-lb)+1\n C_k[:] = view(myC,myk,:)\n end\n # We need to find out the owner of row k.\n # Easy since N is a multiple of P\n root = div(k-1,L)\n MPI.Bcast!(C_k,comm;root)\n # Now, we have the data dependencies and\n # we can do the updates locally\n for j in 1:N\n for i in 1:L\n myC[i,j] = min(myC[i,j],myC[i,k]+C_k[j])\n end\n end\n end\n myC\nend","category":"page"},{"location":"julia_mpi/","page":"MPI (point-to-point)","title":"MPI (point-to-point)","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/julia_mpi.ipynb\"","category":"page"},{"location":"julia_mpi/","page":"MPI (point-to-point)","title":"MPI (point-to-point)","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"julia_mpi/","page":"MPI (point-to-point)","title":"MPI (point-to-point)","text":"\n","category":"page"},{"location":"julia_basics/","page":"Julia Basics","title":"Julia Basics","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/julia_basics.ipynb\"","category":"page"},{"location":"julia_basics/","page":"Julia Basics","title":"Julia Basics","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"julia_basics/","page":"Julia Basics","title":"Julia Basics","text":"\n","category":"page"},{"location":"matrix_matrix/","page":"Matrix-matrix multiplication","title":"Matrix-matrix multiplication","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/matrix_matrix.ipynb\"","category":"page"},{"location":"matrix_matrix/","page":"Matrix-matrix multiplication","title":"Matrix-matrix multiplication","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"matrix_matrix/","page":"Matrix-matrix multiplication","title":"Matrix-matrix multiplication","text":"\n","category":"page"},{"location":"asp/","page":"All pairs of shortest paths","title":"All pairs of shortest paths","text":"EditURL = \"https://github.com/fverdugo/XM_40017/blob/main/notebooks/asp.ipynb\"","category":"page"},{"location":"asp/","page":"All pairs of shortest paths","title":"All pairs of shortest paths","text":"
\n
Tip
\n
\n \n
\n
","category":"page"},{"location":"asp/","page":"All pairs of shortest paths","title":"All pairs of shortest paths","text":"\n","category":"page"},{"location":"","page":"Home","title":"Home","text":"CurrentModule = XM_40017","category":"page"},{"location":"#Programming-Large-Scale-Parallel-Systems-(XM_40017)","page":"Home","title":"Programming Large-Scale Parallel Systems (XM_40017)","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Welcome to the interactive lecture notes of the Programming Large-Scale Parallel Systems course at VU Amsterdam!","category":"page"},{"location":"#What","page":"Home","title":"What","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"This page contains part of the course material of the Programming Large-Scale Parallel Systems course at VU Amsterdam. We provide several lecture notes in jupyter notebook format, which will help you to learn how to design, analyze, and program parallel algorithms on multi-node computing systems. Further information about the course is found in the study guide (click here) and our Canvas page (for registered students).","category":"page"},{"location":"","page":"Home","title":"Home","text":"note: Note\nMaterial will be added incrementally to the website as the course advances.","category":"page"},{"location":"","page":"Home","title":"Home","text":"warning: Warning\nThis page will eventually contain only a part of the course material. The rest will be available on Canvas. In particular, the material in this public webpage does not fully cover all topics in the final exam.","category":"page"},{"location":"#How-to-use-this-page","page":"Home","title":"How to use this page","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"You have two main ways of studying the notebooks:","category":"page"},{"location":"","page":"Home","title":"Home","text":"Download the notebooks and run them locally on your computer (recommended). At each notebook page you will find a green box with links to download the notebook.\nYou also have the static version of the notebooks displayed in this webpage for quick reference.","category":"page"},{"location":"#How-to-run-the-notebooks-locally","page":"Home","title":"How to run the notebooks locally","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"To run a notebook locally follow these steps:","category":"page"},{"location":"","page":"Home","title":"Home","text":"Install Julia (if not done already). More information in Getting started.\nDownload the notebook.\nLaunch Julia. More information in Getting started.\nExecute these commands in the Julia command line:","category":"page"},{"location":"","page":"Home","title":"Home","text":"julia> using Pkg\njulia> Pkg.add(\"IJulia\")\njulia> using IJulia\njulia> notebook()","category":"page"},{"location":"","page":"Home","title":"Home","text":"These commands will open a jupyter in your web browser. Navigate in jupyter to the notebook file you have downloaded and open it.","category":"page"},{"location":"#Authors","page":"Home","title":"Authors","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"This material is created by Francesc Verdugo with the help of Gelieza Kötterheinrich. Part of the notebooks are based on the course slides by Henri Bal.","category":"page"},{"location":"#License","page":"Home","title":"License","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"All material on this page that is original to this course may be used under a CC BY 4.0 license.","category":"page"},{"location":"#Acknowledgment","page":"Home","title":"Acknowledgment","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"This page was created with the support of the Faculty of Science of Vrije Universiteit Amsterdam in the framework of the project \"Interactive lecture notes and exercises for the Programming Large-Scale Parallel Systems course\" funded by the \"Innovation budget BETA 2023 Studievoorschotmiddelen (SVM) towards Activated Blended Learning\".","category":"page"}] }