Skip to content

Commit

Permalink
Version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pnavaro committed Sep 26, 2024
0 parents commit 8ce4b42
Show file tree
Hide file tree
Showing 50 changed files with 1,448 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
30 changes: 30 additions & 0 deletions .github/workflows/quarto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
push:
branches:
- main

name: Render and Publish

permissions:
contents: write
pages: write

jobs:
build-deploy:
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to GitHub Pages
uses: quarto-dev/quarto-actions/publish@v2
with:
target: gh-pages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData
.RDataTmp

# User-specific files
.Ruserdata

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# R Environment Variables
.Renviron

# pkgdown site
docs/

# translation temp files
po/*~

# RStudio Connect folder
rsconnect/
*.swp
/.ipynb_checkpoints
Manifest.toml
index.html
/index_files

/.quarto/
/_site
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Pierre Navaro

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Rmpi : MPI avec le langage R

Supports pour apprendre à utiliser la bibliothèque MPI avec R et le package Rmpi. Cette formation a été dispensée lors de l'Action Nationale de Formation [R pour le calcul](https://indico.mathrice.fr/event/536/) à Fréjus du 23 au 27 septembre 2024

Ces supports reprennent très largement les [supports de cours MPI de l'IDRIS](http://www.idris.fr/formations/mpi/) écrits par Dimitri Lecas, Rémi Lacroix, Serge Van Criekingen et Myriam Peyrounette. J'ai utilisé également les ressources suivantes:

- [Site officiel de Rmpi](https://fisher.stats.uwo.ca/faculty/yu/Rmpi/)
- [How to run R programs on University of Maryland HPC facility](https://hpcf.umbc.edu/other-packages/how-to-run-r-programs-on-maya/)
- [Documentation de GRICAD](https://gricad-doc.univ-grenoble-alpes.fr/hpc/softenv/nix/#r-packages)
- [MPI Tutorial by Wes Kendall](https://mpitutorial.com)
- [CRAN Task View: High-Performance and Parallel Computing with R](https://cran.r-project.org/web/views/HighPerformanceComputing.html)
- [R_note by Wei-Chen Chen](https://snoweye.github.io/R_note/inc_menu/Rmpi.html)

<https://groupecalcul.github.io/ANFRCalculRmpi/>
30 changes: 30 additions & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
project:
type: website

website:
title: ""
description: "Supports du cours Rmpi"
site-url: "https://groupecalcul.github.io/ANFRCalculRmpi"
repo-url: "https://github.com/GroupeCalcul/ANFRCalculRmpi"
repo-actions: [edit, source, issue]
navbar:
logo: src/images/logo.png
left:
- href: src/index.qmd
text: Introduction
- href: src/com_point_a_point.qmd
text: Communications point à point
- href: src/com_collectives.qmd
text: Communications collectives
- href: src/exercice.qmd
text: Conclusion
tools:
- icon: github
href: https://github.com/GroupeCalcul/ANFRCalculRmpi

format:
html:
theme:
light: flatly
dark: darkly
toc: true
16 changes: 16 additions & 0 deletions codes/bcast.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
library(Rmpi)

id <- mpi.comm.rank(comm=0)

# Diffusion du vecteur v sur les processeurs autre que 0
if (id == 0) {
v <- c(1, 2, 3, 4)
mpi.bcast.Robj(obj = v, rank = 0, comm = 0)
} else {
v <- mpi.bcast.Robj(rank = 0, comm = 0)
}

cat("vector on ", id, " = ", v, "\n" )

invisible(mpi.barrier(comm=0))
invisible(mpi.finalize())
25 changes: 25 additions & 0 deletions codes/demo_pbdmpi.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
suppressMessages(library(pbdMPI, quietly = TRUE))
init()

.comm.size <- comm.size()
.comm.rank <- comm.rank()

### Examples.
x <- matrix(1:5, nrow = 1)
y <- bcast(x)
comm.print(x)
comm.print(y)

k <- 10
x <- rep(.comm.rank, k)
comm.cat("\nOriginal x vector:\n", quiet = TRUE)
comm.print(x, all.rank = TRUE)

y <- allgather(x, unlist = TRUE)
A <- matrix(y, nrow = k, byrow = FALSE)
comm.cat("\nAllgather matrix (only showing process 0):\n", quiet = TRUE)
comm.print(A)

### Finish.
finalize()

17 changes: 17 additions & 0 deletions codes/ex_pi_spmd.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# File name: ex_pi_spmd.r
# Run: mpiexec -np 2 Rscript --vanilla ex_pi_spmd.r

### Load pbdMPI and initial the communicator.
library(pbdMPI, quiet = TRUE)
init()

### Compute pi.
n <- 1000
totalcpu <- mpi.comm.size(comm=1)
id <- mpi.comm.rank(comm=1) + 1
mypi <- 4*sum(1/(1+((seq(id,n,totalcpu)-.5)/n)^2))/n # The example from Rmpi.
mypi <- reduce(mypi, op = "sum")

### Output from RANK 0 since mpi.reduce(...) will dump only to 0 by default.
comm.print(mypi)
finalize()
14 changes: 14 additions & 0 deletions codes/hello_mpi.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
program hello

use mpi
implicit none

integer :: rang, nproc, code, ierr
call MPI_INIT(code) !---- Initialisation MPI
call MPI_COMM_RANK(MPI_COMM_WORLD,rang,code) !---- Numero du processus
call MPI_COMM_SIZE(MPI_COMM_WORLD,nproc,code) !---- Nombre total de processus
write(*,*) " rang, nproc", rang, nproc
call MPI_FINALIZE(code)

end program hello

12 changes: 12 additions & 0 deletions codes/hello_mpi.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
library(Rmpi)

id <- mpi.comm.rank(comm=0)
np <- mpi.comm.size(comm=0)
hostname <- mpi.get.processor.name()

msg <- sprintf ("Hello world from task %03d of %03d, on host %s \n", id , np , hostname)
cat(msg)


invisible(mpi.barrier(comm=0))
invisible(mpi.finalize())
27 changes: 27 additions & 0 deletions codes/hello_mpi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <mpi.h>
#include <stdio.h>

int main(int argc, char** argv) {
// Initialize the MPI environment
MPI_Init(NULL, NULL);

// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);

// Get the rank of the process
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

// Get the name of the processor
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);

// Print off a hello world message
printf("Hello world from processor %s, rank %d out of %d processors\n",
processor_name, world_rank, world_size);

// Finalize the MPI environment.
MPI_Finalize();
}
8 changes: 8 additions & 0 deletions codes/hello_mpi.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using MPI

MPI.Init()

comm = MPI.COMM_WORLD
println("Hello world, I am $(MPI.Comm_rank(comm)) of $(MPI.Comm_size(comm))\n")

MPI.Finalize()
12 changes: 12 additions & 0 deletions codes/hello_mpi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python
"""
Parallel Hello World
"""

from mpi4py import MPI

size = MPI.COMM_WORLD.Get_size()
rank = MPI.COMM_WORLD.Get_rank()
name = MPI.Get_processor_name()

print(f"Hello, World! I am process {rank} of {size} on {name}")
14 changes: 14 additions & 0 deletions codes/hello_mpi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
##!/bin/bash
#OAR --project pr-groupecalcul
#OAR -n hello_rmpi
#OAR -l /nodes=1/core=4,walltime=00:01:00
#OAR --stdout hello_mpi.out
#OAR --stderr hello_mpi.err

## Ensure conda is loaded. The following line can be into your ~/.bashrc file.
source /applis/environments/conda.sh

## Run the program
conda activate rmpi
mpirun --np 4 --machinefile $OAR_NODE_FILE --mca plm_rsh_agent "oarsh" $OAR_WORKING_DIRECTORY/hello_mpi
mpirun --np 4 --machinefile $OAR_NODE_FILE --mca plm_rsh_agent "oarsh" Rscript --vanilla $OAR_WORKING_DIRECTORY/hello_mpi.R
13 changes: 13 additions & 0 deletions codes/hello_mpmd.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
library(Rmpi)
mpi.spawn.Rslaves(nslaves = 4, needlog = FALSE)

mpi.bcast.cmd( id <- mpi.comm.rank() )
mpi.bcast.cmd( np <- mpi.comm.size() )
mpi.bcast.cmd( host <- mpi.get.processor.name() )
result <- mpi.remote.exec(paste("I am", id, "of", np, "running on", host))

print(unlist(result))

mpi.close.Rslaves(dellog = FALSE)
mpi.exit()

1 change: 1 addition & 0 deletions codes/install.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install.packages("Rmpi")
14 changes: 14 additions & 0 deletions codes/loop_rowSums.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# File name: loop_rowSums.r

my.loop <- 20
m.dim <- list(nrow = 200000, ncol = 10)
m <- matrix(1, nrow = m.dim$nrow, ncol = m.dim$ncol)
ret <- 0

start <- Sys.time()
for(k in 1 : my.loop){
ret <- ret + sum(rowSums(m))
}
cat(ret, "\n")
Sys.time() - start

29 changes: 29 additions & 0 deletions codes/ping_pong_1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@


library(Rmpi)
nb_valeurs <- 1000
etiquette <- 99

valeurs <- runif(nb_valeurs)

id <- mpi.comm.rank(comm = 0)
np <- mpi.comm.size(comm = 0)

if (id == 0) {
## envoi du message
## ...

} else {
buffer <- numeric(nb_valeurs)

## reception du message
## ...

cat("Moi, processus 1, j''ai recu ",
nb_valeurs,
" valeurs du processus 0. \n")
cat("Premiere valeur ", recv[1], " derniere valeur ", recv[1000], " \n")
}

invisible(mpi.barrier(comm = 0))
invisible(mpi.finalize())
Loading

0 comments on commit 8ce4b42

Please sign in to comment.