Commit 5001afe6 authored by myron's avatar myron

ripulito

parent 7dc97c75
This diff is collapsed.
import time
import numpy
#import random
from numpy import *
from numpy.fft import ifft
from pylab import *
import matplotlib.pyplot as plt
import moduleJL2 as JL2
N = 40
A = JL2.gen_base(N)
[source,b] = JL2.gen_image(N,0.1)
rho = linspace(0.1,1,10)
s = linspace(0.01,0.1,10)
e_FISTA = zeros(10)
e_PRCG = zeros(10)
e_CP = zeros(10)
for i in range(10):
P1 = JL2.Problem(A,b,rho[i],0.01,source)
P1.fista_n(False,True)
e_FISTA[i] = P1.err_F[30]
P1.PR_CG()
e_PRCG[i] = P1.err_CG[30]
P1.CP()
e_CP[i] = P1.err_CP[30]
show()
plot(rho,e_FISTA,'r',label='FISTA')
plot(rho,e_PRCG,'g',label='PR-CG')
plot(rho,e_CP,'c',label='CP')
ylim(0,1)
title('Analyse de l''erreur apres 30 iterations - sigma = 0.1 - s = 0.01')
xlabel("s")
ylabel("erreur")
show()
import time
import numpy
#import random
from numpy import *
from numpy.fft import ifft
from pylab import *
import matplotlib.pyplot as plt
import moduleJL2 as JL2
N = 40
A = JL2.gen_base(N)
[source,b] = JL2.gen_image(N,0.1)
rho = linspace(0.1,1,10)
s = linspace(0.005,0.015,10)
e_FISTA = zeros(10)
e_PRCG = zeros(10)
e_CP = zeros(10)
for i in range(10):
P1 = JL2.Problem(A,b,0.5,s[i],source)
P1.fista_n(False,True)
e_FISTA[i] = P1.err_F[30]
P1.PR_CG()
e_PRCG[i] = P1.err_CG[30]
P1.CP()
e_CP[i] = P1.err_CP[30]
show()
plot(s,e_FISTA,'r',label='FISTA')
plot(s,e_PRCG,'g',label='PR-CG')
plot(s,e_CP,'c',label='CP')
ylim(0,1)
title("Analyse de l'erreur apres 30 iterations - sigma = 0.1 - rho = 0.5")
xlabel("s")
ylabel("erreur")
show()
import time
import numpy
#import random
from numpy import *
from numpy.fft import ifft
from pylab import *
import matplotlib.pyplot as plt
import moduleJL2 as JL2
N = 40
A = JL2.gen_base(N)
[source,b] = JL2.gen_image(N,0.1)
P1 = JL2.Problem(A,b,0.5,0.01,source)
#P1.niter(40)
a=time.clock()
P1.fista_n(False,True)
b=time.clock()
P1.PR_CG()
c=time.clock()
P1.CP()
d = time.clock()
print("FISTA : ",str(b-a))
print("PR_CG : ",str(c-b))
print("CP : ",str(d-c))
x = arange(P1.niter_CG+1)
plot(x,P1.err_F,'r',label='FISTA')
plot(x,P1.err_CG,'g',label='PR-CG')
plot(x,P1.err_CP,'c',label='CP')
legend()
show()
#P1.graph()
// Author : Alessandro Mirone ESRF 2011
// ==============================================================
// COMPILATION :nvcc -arch=sm_20 medianstack.cu -lcudart
// =======================================================
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#include <cuda.h>
#include <fcntl.h>
#include<iostream>
#define DODEBUG 1
#define DEBUG( call ) if(DODEBUG) call ;
#define CUDA_SAFE_CALL_EXCEPTION(call) {do { \
cudaError err = call; \
if( cudaSuccess != err) { \
sprintf(messaggio, "Cuda error in file '%s' in line %i function %s : %s\n", \
__FILE__, __LINE__, __PRETTY_FUNCTION__, cudaGetErrorString( err) ); \
fprintf(stderr, messaggio ); \
goto fail; \
} } while (0); }
// -----------------------------------------------------------------------------------------------
// estimation of shared size : 1 + 2*DIMBLOCK*( ((nimages-1)/2) ) + 2*(DIMBLOCK-1) +1
template<int shared_size>
__global__ static void cuda_medianstack_kernel(int nimages,
int isize_padded ,
unsigned short* buffer,
unsigned short* target_buffer
) {
__shared__ unsigned short data[ shared_size ] ;
unsigned short tmp, prefetched;
const int bidx = blockIdx.x;
const int tidx = threadIdx.x;
const int bdim = blockDim.x ;
#define DATA(i) data[ (i)%2 + 2*bdim*( (i)/2 ) + tidx*2 ]
int i_im=0;
prefetched = buffer[ bdim* bidx + tidx+ i_im* isize_padded ] ;
for( i_im=0; i_im<nimages; i_im++) {
DATA(i_im)= prefetched;
syncthreads();
if( i_im<nimages-1) {
prefetched = buffer[ bdim* bidx + tidx+ (i_im+1)* isize_padded ] ;
}
for(int k=i_im; k>0; k--) {
if( DATA(k)<DATA(k-1) ) {
tmp = DATA(k) ;
DATA(k)=DATA(k-1);
DATA(k-1) = tmp ;
}
}
}
syncthreads();
target_buffer[ bdim* bidx + tidx ] = DATA( (nimages/2)) ;
}
typedef struct cuda_medianstack{
int isize, isize_padded;
int nimages ;
int index ;
int completeness ;
unsigned short * buffer;
unsigned short * target_buffer;
} cuda_medianstack;
void cuda_medianstack_finish( cuda_medianstack* self ) {
char messaggio[10000];
CUDA_SAFE_CALL_EXCEPTION(cudaFree ( self->buffer ) );
fail :
throw messaggio ;
}
void cuda_medianstack_getMedian( cuda_medianstack* self, unsigned short * image_res ) {
char messaggio[10000];
if(!self->completeness) {
sprintf(messaggio, " problem : you asked a median befores filling all the buffers in file '%s' in line %i \n", __FILE__, __LINE__ );
throw messaggio;
}
int tileX = 256 ;
dim3 dimGrid ( self->isize_padded/tileX + (( self->isize_padded % tileX )>0) );
dim3 dimBlock ( tileX );
float cuTime_ms;
cudaEvent_t event_s,event_e;
cudaEventCreate(&event_s);
cudaEventCreate(&event_e);
cudaEventRecord(event_s);
// estimation of shared size : 1 + 2*DIMBLOCK*( ((nimages-1)/2) ) + 2*(DIMBLOCK-1) +1
int estimation = 1 + 2*tileX*( ((self->nimages-1)/2) ) + 2*(tileX-1) +1 ;
if( estimation<=1024) {
cuda_medianstack_kernel<1024><<<dimGrid,dimBlock>>> ( self->nimages, self->isize_padded , self->buffer, self->target_buffer );
} else if( estimation<=2048) {
cuda_medianstack_kernel<2048><<<dimGrid,dimBlock>>> ( self->nimages, self->isize_padded , self->buffer, self->target_buffer );
} else if( estimation<=4096) {
cuda_medianstack_kernel<4096><<<dimGrid,dimBlock>>> ( self->nimages, self->isize_padded , self->buffer, self->target_buffer );
} // else {
// sprintf(messaggio, " You have to recompile with a larger shared memory " );
// goto fail;
// }
else if( estimation<=8192) {
cuda_medianstack_kernel<8192><<<dimGrid,dimBlock>>> ( self->nimages, self->isize_padded , self->buffer, self->target_buffer );
} else if( estimation<=8192*2) {
cuda_medianstack_kernel<16384 ><<<dimGrid,dimBlock>>> ( self->nimages, self->isize_padded , self->buffer, self->target_buffer );
} else {
sprintf(messaggio, " You have to recompile with a larger shared memory " );
goto fail;
}
cudaEventRecord(event_e);
cudaEventSynchronize(event_s);
cudaEventSynchronize(event_e);
cudaEventElapsedTime(&cuTime_ms,event_s,event_e);
std::cout << __FUNCTION__ << " elapsed time: " << cuTime_ms << " (ms) " << std::endl;
cudaEventDestroy(event_e);
cudaEventDestroy(event_s);
CUDA_SAFE_CALL_EXCEPTION(cudaMemcpy ( image_res , self->target_buffer ,
self->isize*sizeof(unsigned short) , cudaMemcpyDeviceToHost ) );
return ;
fail :
throw messaggio ;
}
void cuda_medianstack_addImage( cuda_medianstack* self, unsigned short * image ) {
char messaggio[10000];
CUDA_SAFE_CALL_EXCEPTION(cudaMemcpy ( self->buffer +self->index* self->isize_padded , image ,
self->isize_padded*sizeof(unsigned short) , cudaMemcpyHostToDevice ) );
self->index=self->index+1;
if(self->index==self->nimages) {
self->index=0;
self->completeness=1;
}
return ;
fail :
throw messaggio ;
}
cuda_medianstack *cuda_medianstack_init( int Nimages, int size_image ) {
cuda_medianstack * res = new cuda_medianstack ;
res->nimages = Nimages;
res->isize = size_image;
res->isize_padded = 32*ceil(size_image/32.0);
res->index = 0;
res->completeness=0;
res->buffer=0;
res->target_buffer=0;
char messaggio[10000];
int dev;
cudaDeviceProp prop;
CUDA_SAFE_CALL_EXCEPTION( cudaGetDevice(&dev));
DEBUG(printf(" il device utilizzato est %d \n", dev );)
CUDA_SAFE_CALL_EXCEPTION(cudaGetDeviceProperties( &prop,dev));
DEBUG(printf("CHOSEN DEVICE %s \n", prop.name ));
DEBUG(printf(" la shared mem per block est %d ( bytes)\n", prop.sharedMemPerBlock););
DEBUG(printf(" la totalConstMem; est %d ( bytes)\n", prop.totalConstMem););
CUDA_SAFE_CALL_EXCEPTION( cudaMalloc((void**)&res->buffer , sizeof(unsigned short) *res->nimages* res->isize_padded ));
CUDA_SAFE_CALL_EXCEPTION( cudaMalloc((void**)&res->target_buffer , sizeof(unsigned short) * res->isize_padded ));
return res;
fail :
if(res->buffer ) cudaFree(res->buffer );
if(res->target_buffer ) cudaFree(res->target_buffer );
throw messaggio ;
}
main() {
struct cuda_medianstack * stack;
int Nimages=21;
int size_image=2048*2048;
unsigned short * image = new unsigned short [size_image] ;
unsigned short * res_image = new unsigned short [size_image] ;
stack = cuda_medianstack_init( Nimages, size_image ) ;
for(int i=0; i< Nimages; i++) {
for(int k=0; k<size_image; k++) {
image[k] = (i*23)%Nimages ;
}
try {
printf("%d ", image[0]);
cuda_medianstack_addImage( stack, image);
} catch (char *message) {
std::cout << " I received this exception message " << message << std::endl ;
exit(0);
}
}
printf("\n launching median \n");
for(int volta=0; volta<100; volta++) {
try {
for(int k=0; k<size_image; k++) {
image[k] = volta%21 ;
}
cuda_medianstack_addImage( stack, image);
cuda_medianstack_getMedian( stack, res_image);
} catch (char *message) {
std::cout << " I received this exception message " << message << std::endl ;
exit(0);
}
printf(" RESULTS %d %d %d \n" , res_image[0], res_image[132], res_image[2048*1000]);
}
}
import sys
s=sys.argv[1]
p=s.find("(")
s=s[:p]
print(s)
exec(s.strip())
assert(exit_code==0)
export TD=~/packages/
# export TD=/tmp_14_days/mirone/
mkdir $TD
rm ${TD}/scripts/PyHST
python3 setup.py install --prefix ${TD}
#--install-lib ${TD}/libs
# --install-scripts ${TD}/scripts
# mv ${TD}/scripts/PyHST ${TD}/scripts/PyHSTlauncher
# cat > ${TD}/scripts/PyHST << EOF
# #!/bin/bash
# export PYTHONPATH=${TD}/libs/:\$PYTHONPATHPATH
# export PATH=${TD}/scripts/:\$PATH
# PyHSTlauncher \$*
# EOF
# chmod a+x ${TD}/scripts/PyHST
# export CUDAHOME=/usr/local/cuda-4.0.17
export TD=/scisoft/ESRF_sw/opteron2/PACKAGES/PyHST_2_experimental
# export TD=${PWD}/dummy/
mkdir $TD
python setup.py install --install-lib ${TD}/libs --install-scripts ${TD}/scripts
cat > ${TD}/scripts/PyHST << EOF
#!/bin/bash
source /scisoft/ESRF_sw/opteron2/set_environment
cudaversion=4
nofbits=64
Ncudadir=\`ls -td /usr/local/cuda-\${cudaversion}* 2>/dev/null | wc -l\`
if [ "\$Ncudadir" != "0" ] ; then
cudadir=\`ls -td /usr/local/cuda-\${cudaversion}* 2>/dev/null | head -1\`
else
cudadir="/usr/local/cuda"
fi
n=`ls -td \${cudadir}/lib64 2>/dev/null | wc -l `
if [ "\$nofbits" == "64" ] ; then
export LD_LIBRARY_PATH=/usr/lib64:\${LD_LIBRARY_PATH}
fi
if [ "\${cudadir}" != "" ]; then
if [ "\$nofbits" == "64" -a "\$n" == "1" ] ; then
export LD_LIBRARY_PATH=\${cudadir}/lib64:\${LD_LIBRARY_PATH}
else
export LD_LIBRARY_PATH=\${cudadir}/lib:\${LD_LIBRARY_PATH}
fi
fi
export PYTHONPATH=${TD}/libs/:\$PYTHONPATHPATH
export PATH=${TD}/scripts/:\$PATH
PyHSTlauncher \$*
EOF
chmod a+x ${TD}/scripts/PyHST
cat > ${TD}/scripts/pyhst << EOF
#!/bin/bash
source /scisoft/ESRF_sw/opteron2/set_environment
cudaversion=4
nofbits=64
Ncudadir=\`ls -td /usr/local/cuda-\${cudaversion}* 2>/dev/null | wc -l\`
if [ "\$Ncudadir" != "0" ] ; then
cudadir=\`ls -td /usr/local/cuda-\${cudaversion}* 2>/dev/null | head -1\`
else
cudadir="/usr/local/cuda"
fi
n=`ls -td \${cudadir}/lib64 2>/dev/null | wc -l `
if [ "\$nofbits" == "64" ] ; then
export LD_LIBRARY_PATH=/usr/lib64:\${LD_LIBRARY_PATH}
fi
if [ "\${cudadir}" != "" ]; then
if [ "\$nofbits" == "64" -a "\$n" == "1" ] ; then
export LD_LIBRARY_PATH=\${cudadir}/lib64:\${LD_LIBRARY_PATH}
else
export LD_LIBRARY_PATH=\${cudadir}/lib:\${LD_LIBRARY_PATH}
fi
fi
export PYTHONPATH=${TD}/libs/:\$PYTHONPATHPATH
export PATH=${TD}/scripts/:\$PATH
pyhstlauncher \$*
EOF
chmod a+x ${TD}/scripts/pyhst
cat > ${TD}/scripts/PyHSTlauncher << EOF
#!/scisoft/ESRF_sw/opteron2/bin/python
import PyHST
import PyHST.PyHST
EOF
chmod a+x ${TD}/scripts/PyHSTlauncher
cat > ${TD}/scripts/pyhstlauncher << EOF
#!/scisoft/ESRF_sw/opteron2/bin/python
import PyHST
import PyHST.pyhst
EOF
chmod a+x ${TD}/scripts/pyhstlauncher
This diff is collapsed.
import sys
s=sys.argv[1]
exec(s.split("\n")[-1])
print OAR_JOB_ID
export LD_PRELOAD=/scisoft/ESRF_sw/opteron2/lib/libmpi.so
pylancia
# mpirun --mca rmaps seq --mca plm_rsh_agent "ssh -X" -machinefile machinefile -n 1 --byslot python provampicpuset.py
1003 git status
1004 git branch -a
1005 git checkout -b experimental
1006 git status
1007 gitk
1008 git remote -v
1009 git remote add origin git@git.epn-campus.eu:chst
1010 git remote
1011 git remote -v
1012 git help push
1013 git push origin experimental
1014 git branch -a
1015 git branch -a --color
1016 git checkout master
1017 git pull
1018 ssh-add
1019 ssh-agent bash
1000 ssh-add
1001 fir branch -a
1002 git branch -a
1003 git pull
1004 git pull origin master
1005 git branch -a
1006 git checkout experimental
1007 git pull
1008 git pull origin experimental
1009 git pull
1010 vim .git/config
1011 git gui
1012 git branch -a
1013 wget https://raw.github.com/github/gitignore/master/C.gitignore
1014 vim .gitignore
1015 git status
1016 git add .gitignore
1017 git status
1018 git commit -m 'add gitignore'
1020 git branch -a
1021 git checkout experimental
1023 git push
1024 git checkout experimental
1025 git log
1026 git log master
1027 git log --graph
1028 git merge master
1029 git log
1030 git log --color --graph
1031 gitk
1032 git checkout -t master
1033 git checkout -t -b master
1034 git branch --set-upstream master origin/master
1035 git branch --set-upstream experimental origin/experimental
1036 git branch
1037 git pull
1038 git branch
1039 git checkout master
1040 git status
1044 git add .gitignore
1045 git status | more
1046 git commit -m " ignoring TEST directories "
1047 vi .gitignore
1049 git status
1050 git add .gitignore
1051 git commit -m " ignoring installation directories "
1052 git push
1053 git checkout experimental
1054 git log master
1055 git cherry-pick d4d9713622a
1056 ls
1057 git status
1058 vim .gitignore
1059 git add .gitignore
1060 git commit -c d4d9713622a
1061 gitk
1062 git checkout master
1063 gitk
1064 git diff experimental master
1065 git diff experimental experimental
1066 git diff experimental ^experimental
1067 git diff HEAD ^HEAD
1068 git help diff
1069 cd .git
1071 ls --color
1072 cd refs
1073 ls
1074 ls heads
1075 cd heads
1076 ls
1077 file *
1078 cat master
1079 cd ../
1080 ls
1081 cd remotes
1082 ls
1083 cat origin
1084 cat origin/master
1085 cd ..
1086 ls
1087 cd ..
1088 ls
1089 cd objects/
1090 ls
1091 ls --color
1092 cd d4/
1093 ls
1094 file d9713622a7385ec97e51a6dbb25bb814eb8e6f
1095 cd ..
1096 cd ..
1097 ls
1098 cat COMMIT_EDITMSG
1099 ls
1100 cat config
1101 cd ..
1102 git config --global user.name "Alessandro Mirone"
1103 gitk
1104 git status
1105 history > lesson_thomas.txt
#/*##########################################################################
# Copyright (C) 2001-2013 European Synchrotron Radiation Facility
#
# PyHST2
# European Synchrotron Radiation Facility, Grenoble,France
#
# PyHST2 is developed at
# the ESRF by the Scientific Software staff.
# Principal author for PyHST2: Alessandro Mirone.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# PyHST2 is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# PyHST2; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307, USA.
#
# PyHST2 follows the dual licensing model of Trolltech's Qt and Riverbank's PyQt
# and cannot be used as a free plugin for a non-free program.
#
# Please contact the ESRF industrial unit (industry@esrf.fr) if this license
# is a problem for you.
#############################################################################*/
#include<stdio.h>
# include <unistd.h>