Skip to content

Instantly share code, notes, and snippets.

View scemama's full-sized avatar
🏠
Working from home

Anthony Scemama scemama

🏠
Working from home
View GitHub Profile
@scemama
scemama / system_clock.f90
Created March 1, 2015 10:02
System clock
integer*8 :: cpu0, cpu1, count_rate, count_max
call system_clock(cpu0, count_rate, count_max)
! ...
call system_clock(cpu1, count_rate, count_max)
print *, real(cpu1-cpu0)/real(count_rate)
@scemama
scemama / progress.f90
Created February 25, 2015 09:29
Progress monitor in Fortran
module progress
implicit none
! A value you want to monitor (like a running average for instance)
real*8 :: progress_value = huge(1.d0)
! the 1st index will contain the current loop count, and the 2nd index the
! total loop count. The ratio ``dble(progress_bar(1))/dble(progress_bar(2))``
! will give you the current percentage of progress.
integer :: progress_bar(2) = (/ 1, 1 /)
@scemama
scemama / backup_vm.sh
Created January 26, 2015 10:02
Backup a VM
#!/bin/bash
MACHINE=$1
DESTINATION="/backup/VMs/"
DATE=$(date +"%F")
LONG_DATE=$(date)
cd $HOME
@scemama
scemama / restart_vms.sh
Created January 26, 2015 10:00
Cron to keep VMs on
#!/bin/bash
VMS=$(VBoxManage list vms | cut -d ' ' -f 1 | tr '"' ' ')
for VM in $VMS
do
VBoxManage list runningvms | cut -d ' ' -f 1 | grep $VM > /dev/null
if [[ $? -ne 0 ]]
then
VBoxManage startvm $VM --type=headless
@scemama
scemama / add-travis.md
Last active August 29, 2015 14:14 — forked from mbohun/add-travis.md
@scemama
scemama / gist:302c03ec9ef51f441b6e
Created January 26, 2015 09:44
Call a fortran sburoutine from a C main
$ gcc fort_file.o c_file.o -lifcore -lirc -lcomposerxe_gen_helpers_core_2.3
@scemama
scemama / pipe.ml
Created January 26, 2015 09:42
Ocaml pipe operator
let (|>) x f = f x ;;
"Hello" |> print_endline;;
@scemama
scemama / lu.f90
Created January 26, 2015 09:41
LU factorization
subroutine LU_factorization(m,n,A,LDA,L,LDL,U,LDU)
implicit none
integer, intent(in) :: m,n
integer, intent(in) :: LDA,LDU,LDL
double precision, intent(in) :: A(LDA,n)
double precision, intent(out) :: L(LDL,n), U(LDU,n)
integer :: i,j
integer :: iswap, info
integer,allocatable :: ipiv(:), iorder(:)
@scemama
scemama / rdtsc.c
Created January 26, 2015 09:38
Read time stamp counter
#ifdef __i386
double rdtsc_(void) {
unsigned long long x;
__asm__ volatile ("rdtsc" : "=A" (x));
return (double) x;
}
#elif __amd64
double rdtsc_(void) {
unsigned long long a, d;
__asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
@scemama
scemama / create_random_matrix.f90
Created January 26, 2015 09:37
Create a random matrix
subroutine create_random_matrix(m,n,A,LDA)
implicit none
integer, intent(in) :: m,n
integer, intent(in) :: LDA
double precision, intent(out) :: A(LDA,n)
integer :: i,j
do j=1,n
do i=1,m
call random_number( A(i,j) )