4 algoritmi pentru planificarea proceselor (sistem cu un singur procesor:) ):
1) First come, first served
2) Shortest Job First
3) Shortest Remaining time first
4) Round Robin
Se gasesc aici .
Pentru detalii de rulare, cititi fisierul de Readme.
27 mai 2011
20 mai 2011
Calcularea inversei unei matrici
EXEMPLU
COMPILARE
#include "lapack.h"
int main( int argc, char *argv[] )
{
int info = 0;
double *a;
int *ipiv;
int n;
int i,j;
if( argc < 2 )
{
fprintf(stderr, "%s N\n", argv[0]);
return 0;
}
n = atoi(argv[1]);
posix_memalign((void **)((void*)(&ipiv)), 128, sizeof(int)*n);
posix_memalign((void **)((void*)(&a)), 128, sizeof(double)*n*n);
if( a == NULL || ipiv == NULL )
{
fprintf(stderr, "a/ipiv malloc error\n");
return 0;
}
for( i = 0; i < n; i++ )
for( j = 0; j < n; j++ )
a[i+j*n]= (drand48() - 0.5f)*4;
for( i = 0; i < n; i++ )
for( j = 0; j < n; j++ )
printf("%2.1f ",a[i+j*n]);
printf("\n");
/*---------Call Cell LAPACK library---------*/
dgetrf_(&n, &n, a, &n, ipiv, &info);
if( info != 0 )
{
fprintf(stderr, "Call dgetrf error\n");
goto end;
}
printf("getrf_ \n");
for( i = 0; i < n; i++ )
{
for( j = 0; j < n; j++ )
printf("%2.1f ",a[i+j*n]);
printf("\n");
}
/*---------Query workspace-------*/
double workspace;
int tmp=-1;
int lwork;
double *work;
dgetri_(&n, a, &n, ipiv, &workspace, &tmp, &info);
lwork = (int)workspace;
work = malloc(sizeof(double)*lwork);
if(work == NULL)
{
printf("work malloc error\n");
goto end;
}
printf("getri_ (1)\n");
for( i = 0; i < n; i++ )
{
for( j = 0; j < n; j++ )
printf("%2.1f ",a[i+j*n]);
printf("\n");
}
/*---------Call Cell LAPACK library---------*/
dgetri_(&n, a, &n, ipiv, work, &lwork, &info);
if( info != 0 )
{
fprintf(stderr, "Call dgetri error\n");
free(work);
goto end;
}
printf("Inverse matrix completed!\n");
printf("getri_ (2)\n");
for( i = 0; i < n; i++ )
{
for( j = 0; j < n; j++ )
printf("%2.1f ",a[i+j*n]);
printf("\n");
}
end:
free(ipiv);
free(a);
return 0;
}
COMPILARE
gcc inverse.c -o inverse -llapack -lblas -lm
11 mai 2011
06 mai 2011
Exercitii Oracle/SQL+
Trupele care n-au avut concerte in aceeasi statiune mai mult de o data la 2 ani si care n-au avut niciun concert in ultimul an. (au avut concerte in aceeasi statiune dupa o perioada mai mare de 2 ani de la concertul precedent si n-au avut niciun concert in ultimul an )
Rezultat dorit: Narcotic
-------------------------- mai multe aici ---------------------------------------
Click pe full screen
Rezultat dorit: Narcotic
create table trupe (id number(2) primary key, nume varchar2(30) check (nume = initcap(nume)));
create table statiuni (id number(2) primary key, nume varchar2(30) check (nume = initcap(nume)));
create table concerte (idc number(2) primary key, idt number(2) references trupe(id), ids number(2) references statiuni(id), data date);
insert into trupe values (1, 'Vama');
insert into trupe values (2, 'Voltaj');
insert into trupe values (3, 'Narcotic');
insert into trupe values (4, 'Habibwahid');
insert into statiuni values (1, 'Saidia');
insert into statiuni values (2, 'Antalya');
insert into statiuni values (3, 'Chittagong');
insert into statiuni values (4, 'Albena');
insert into concerte values (1, 1, 2, '5-JUN-03');
insert into concerte values (2, 1, 2, '5-JUN-05');
insert into concerte values (3, 2, 4, '5-JUN-07');
insert into concerte values (4, 3, 4, '6-JUN-00');
insert into concerte values (5, 4, 1, '5-JUN-07');
insert into concerte values (6, 4, 3, '5-JUN-09');
insert into concerte values (7, 4, 2, '5-AUG-10');
insert into concerte values (8, 2, 4, '5-JUN-10');
insert into concerte values (9, 3, 4, '5-JUN-04');
select nume from trupe
where id NOT IN
(select DISTINCT c1.idt
from concerte c1, concerte c2
where (c1.idc != c2.idc AND abs(c1.data-c2.data)/365.5<=2 AND c1.ids = c2.ids)
OR (sysdate-c1.data)/365<1 );
-------------------------- mai multe aici ---------------------------------------
Click pe full screen
Operatii pe vectori si matrici, folosind CPU si GPU
1. Dublarea fiecarui element al unui vector, in mod normal si prin cuda. (doubleArr.cu)
2. Adunarea a doua matrici, in mod normal si prin cuda. (matadd.cu)
Link: http://dl.dropbox.com/u/24465060/Cuda_Ex.zip
Rezultatul returnat reprezinta echivalenta valorilor calculate pe CPU fata de cele calculate in GPU.
Compilarea se face:
2. Adunarea a doua matrici, in mod normal si prin cuda. (matadd.cu)
Link: http://dl.dropbox.com/u/24465060/Cuda_Ex.zip
Rezultatul returnat reprezinta echivalenta valorilor calculate pe CPU fata de cele calculate in GPU.
Compilarea se face:
nvcc fisier.cu -o fisier
./fisier
05 mai 2011
Script pt schimbarea desktop image
Un script care seteaza wallpaperul (cu o frecventa de 2 minute). Puteti folosi una, doua, ..mai multe imagini care sa se succeada (in exemplu se succed 2 imagini). Atentie la cai.
(( pentru ca comanda sleep sa fie recunoscuta, aveti nevoie sa instalati Windows Server 2003 Resource Kit Tools ))
Daca suplimentar doriti sa rulati fisierul bat ca un serviciu (independent de consola), programul AlwaysUp poate fi util ;)
@ECHO OFF
set /a var = 0
:start
:: Adds the necessary Registry values, in case this person is using a System Wallpaper. If they've already customized their wallpaper, the following lines are not necessary. They won't hurt though.
if %var% == 0 (
REG ADD "HKCU\Control Panel\Desktop" /V Wallpaper /T REG_SZ /F /D "C:\poza_1.jpg"
) else (
REG ADD "HKCU\Control Panel\Desktop" /V Wallpaper /T REG_SZ /F /D "C:\poza_2.jpg"
)
set /a var = 1 - %var%
:: Change the last number in the following line to a 0 if you want to center the bitmap on the desktop. Change the last number in the following line to a 2 if you want to stretch the bitmap vertically and horizontally to fit the desktop.
REG ADD "HKCU\Control Panel\Desktop" /V WallpaperStyle /T REG_SZ /F /D 2
:: Change the last number in the following line to a 0 to not tile the image; setting it to a 1 Tiles it.
REG ADD "HKCU\Control Panel\Desktop" /V TileWallpaper /T REG_SZ /F /D 0
:: The following line refreshes the desktop.
%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters
:: sleep 2 minute
sleep 120
GOTO start
Daca suplimentar doriti sa rulati fisierul bat ca un serviciu (independent de consola), programul AlwaysUp poate fi util ;)
01 mai 2011
Exemplu afisare timp intre executii
#include "stdio.h"
#include "time.h"
int main()
{
time_t t1, t2;
t1 = time(0);
sleep(2);
t2 = time(0);
printf("Elapsed: %d\n", t2 - t1);
}
#include "time.h"
int main()
{
time_t t1, t2;
t1 = time(0);
sleep(2);
t2 = time(0);
printf("Elapsed: %d\n", t2 - t1);
}
Abonați-vă la:
Postări (Atom)