Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Test Brzine procesora - "besposlen pop jarice krsti"

[es] :: Linux aplikacije :: Test Brzine procesora - "besposlen pop jarice krsti"

Strane: < .. 1 2 3 4 5 6

[ Pregleda: 26516 | Odgovora: 119 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Branimir Maksimovic

Član broj: 64947
Poruke: 5534
c-bg-d-p6-19.bvcom.net.



+1064 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"04.11.2008. u 13:30 - pre 188 meseci
Nije dual brzi od quada nego je problem sto je memory bus za quad isti kao na dual-u, pa aplikacija
koja zesce drlja po ramu jednostavno pokazuje da na quadu cak i gubis zato sto
se procesori kolju oko rama, tj bus mu je bottleneck.

Amd ima brzi bus od intela- i u ovom benchu je presudan faktor brzina
bus-a a ne ghz ili performanse samog jezgra.
Tvoj quad ima front sajd bas od 333mhz i to ga kolje, dok amd-ovi imaju interni memorijski kontroler
pa ne znam kako se oni rejtuju, ali ocigledno negde oko 400mhz posto sam na tolko overklokovao
svoj intel. Sama ghz-aza ne utice toliko.
Voleo bih da vidim nekog sa phenom-om x4 u ganged i not ganged modu. U ovom bench-u quad phenom
bi trebao sve da oduva, naravno ukoliko mu je bas znatno brzi.

Pozdrav!
 
Odgovor na temu

Srđan Pavlović
Specijalna Edukacija i Rehabilitacija MNRO
Vojvodina, Bačka Palanka

Član broj: 139340
Poruke: 5571
79.101.182.*

Sajt: www.oligofrenolog.com


+382 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"05.11.2008. u 16:59 - pre 188 meseci
srdjan@Zverko:~$ time ./test-2-run (Branimirov test)
25 percent done:
50 percent done:
75 percent done:
100 percent done - Test completed!

real 0m8.495s
user 0m15.769s
sys 0m0.128s
srdjan@Zverko:~$

Intel C2D, E6850 3Ghz (stock), 4mb cache, 6000 bogomips.
 
Odgovor na temu

combuster
Ivan Bulatovic
Kraljevo

Član broj: 151351
Poruke: 4563
79.101.80.*

Sajt: www.linuxsrbija.org


+104 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 10:02 - pre 188 meseci
@branimir

Cekaj, ti si zaglavlje semaphore koristio za signalizaciju kada je funkcija tf obavila posao da bi ispisao pravilno procente, kreirao si cetiri thread-a i prosledio argument mem+0*BLCK_SIZE funkciji tf u prvom thread-u itd... Znas sta mi jedino nije jasno (makar se nadam da mi samo to nije jasno :D)?

void* tf(void* p)
{
int j = 80;
while(j--)
{
int i = 0;
for(;i<BLCK_SIZE;++i)
{
*((int*)p+i) = i;
}
if(j%20==0)
{
sem_post(&sema);
sem_wait(&sema1);
}
}
return 0;
}


Ovde si proveravao ostatak da bi prosledio signal za semafor na svakih 25% a mem+0*BLCK_SIZE se prosledjuje promenljivoj p. E sad sta mene kopka:
*((int*)p+i) = i; dakle (int*)p + i ti daje memorijsku adresu koja sadrzi integer vrednost koja se dodeljuje promenljivoj i i koja se uvecava za jedan sve dok ne dostigne deklarisani block size ili ide kontra - (int*)p + i ti daje integer vrednost cija memorijska adresa se dodeljuje promenljivoj i i ta adresa se uvecava za jedan dok ne dostigne BLCK_SIZE?

Malko sam se pogubio u pointerima...

make love - !war
 
Odgovor na temu

Branimir Maksimovic

Član broj: 64947
Poruke: 5534
c-bg-d-p6-36.BVCOM.NET.



+1064 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 10:42 - pre 188 meseci
U c-u indeksiranje ide preko pointer aritmetike, dakle,
Code:

((int*)p)[i]

je ekvivalentno *((int*)p+i),
pa (int*)p+i daje pointer, a to ti je memorijsak adresa. Operator * daje sadrzaj adrese, tj dereferencira
pointer.

Sto se semafora tice, da, na svakih 25% f-ja prvo signalizira da je zavrsila a onda ceka
na signal da nastavi dalje.

Jel sad jasnije?


Pozdrav!
 
Odgovor na temu

combuster
Ivan Bulatovic
Kraljevo

Član broj: 151351
Poruke: 4563
79.101.80.*

Sajt: www.linuxsrbija.org


+104 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 11:09 - pre 188 meseci
Pointer od pointera :D Ok, sad mi je jasno, znaci ipak u i smestas sadrzaj adrese a ne samu adresu...
Thnx...

A evo rezultata...

combuster@vostro:~/test$ time ./test
25 percent done:
50 percent done:
75 percent done:
100 percent done - Test completed!

real 0m11.831s
user 0m22.529s
sys 0m0.148s


Mobile Core2Duo T5670 1.8 GHz, 2GB RAM-a...

Ako hoces 3GB RAM-a da alociras stavlja se pri definiciji BLCK_SIZE vrednost od 201326592 jel tako?

[Ovu poruku je menjao combuster dana 06.11.2008. u 12:43 GMT+1]
make love - !war
 
Odgovor na temu

Srđan Pavlović
Specijalna Edukacija i Rehabilitacija MNRO
Vojvodina, Bačka Palanka

Član broj: 139340
Poruke: 5571
93.86.118.*

Sajt: www.oligofrenolog.com


+382 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 11:45 - pre 188 meseci
srdjan@Zverko:~$ gcc -Wall -lpthread -O2 test-2.c -o test-2-run
srdjan@Zverko:~$ time ./test-2-run
25 percent done:
50 percent done:
75 percent done:
100 percent done - Test completed!

real 1m39.985s
user 3m9.312s
sys 0m1.908s
srdjan@Zverko:~$


201326592 BLCK_SIZE


Bogami, sad sam cuo i ventilator iz kucista ;)


 
Odgovor na temu

combuster
Ivan Bulatovic
Kraljevo

Član broj: 151351
Poruke: 4563
79.101.80.*

Sajt: www.linuxsrbija.org


+104 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 11:57 - pre 188 meseci
Code:


#include <stdlib.h>
#include <semaphore.h>
#include <pthread.h>
#include <stdio.h>

#define BLCK_SIZE 16777216

sem_t sema,sema1;

void* tf(void* p)
{
  int j = 80;
  while(j--)
  {
    int i = 0;
    for(;i<BLCK_SIZE;++i)
    {
      *((int*)p+i) = i;
    }
    if(j%20==0)
    {
      sem_post(&sema);
      sem_wait(&sema1);
    }
  }
  return 0;
}

int main ()
{
  sem_init(&sema,0,0);
  sem_init(&sema1,0,0);
  
  int* mem = calloc(4,BLCK_SIZE*sizeof(int));
  int d = 0.000015259 * BLCK_SIZE;
  if(!mem)
  {
    printf("not enough memory\n");
    return 0;
  }
  else printf("program allocated %d MB of RAM\n", d);

  pthread_t tid[4];

  pthread_create(tid+0,0,tf,mem+0*BLCK_SIZE);
  pthread_create(tid+1,0,tf,mem+1*BLCK_SIZE);
  pthread_create(tid+2,0,tf,mem+2*BLCK_SIZE);
  pthread_create(tid+3,0,tf,mem+3*BLCK_SIZE);

  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf ("25 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("50 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("75 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("100 percent done - Test completed!\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  pthread_join(tid[0],NULL);
  pthread_join(tid[1],NULL);
  pthread_join(tid[2],NULL);
  pthread_join(tid[3],NULL);

  free(mem);
  sem_destroy(&sema);
  sem_destroy(&sema1);

  return 0;
}


Ispisace vam koliko memorije alocira...
Sad cu da vidim da napravim i da korisnik ukuca kolicinu memorije za alokaciju... U MB...
make love - !war
 
Odgovor na temu

Srđan Pavlović
Specijalna Edukacija i Rehabilitacija MNRO
Vojvodina, Bačka Palanka

Član broj: 139340
Poruke: 5571
93.86.118.*

Sajt: www.oligofrenolog.com


+382 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 12:03 - pre 188 meseci
ajd da neko implementira u sam program merenje vremena da se izbegne ovo startovanje sa time...


Evo 64-bit izvrsni samo za 201326592 BLCK_SIZE, na srpskom :D

srdjan@Zverko:~$ time ./test-2-run
Alocirano 3072 MB RAM memorije...
25 percent done:
50 percent done:
75 percent done:
100 percent done - Test kompletiran!

real 1m40.002s
user 3m9.208s
sys 0m1.948s
srdjan@Zverko:~$

/edit: parcijalno prevedeno... :D

[Ovu poruku je menjao Kernel-1 dana 06.11.2008. u 13:17 GMT+1]
Prikačeni fajlovi
 
Odgovor na temu

combuster
Ivan Bulatovic
Kraljevo

Član broj: 151351
Poruke: 4563
79.101.80.*

Sajt: www.linuxsrbija.org


+104 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 12:14 - pre 188 meseci

int BLCK_SIZE;
int memory;
printf("Unesite vrednost memorije za alokaciju u MB:");
scanf("%d", &memory);
BLCK_SIZE = memory * 65536;
return BLCK_SIZE;


e sad kako da namestim da mi bude public BLCK_SIZE posto ga koristis i u tf i u main, to mi je sad problematicno...
make love - !war
 
Odgovor na temu

combuster
Ivan Bulatovic
Kraljevo

Član broj: 151351
Poruke: 4563
212.200.195.*

Sajt: www.linuxsrbija.org


+104 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 16:30 - pre 188 meseci
Code:

#include <stdlib.h>
#include <semaphore.h>
#include <pthread.h>
#include <stdio.h>

sem_t sema,sema1;

int memparse ();
int memload ();

int memparse()
{
  int d;
  int i;
  i = memload ();
  d = i * 65536;
  return d;
}

int memload()
{
  int memory;
  scanf("%d", &memory);
  return memory;
}

void* tf(void* p)
{
  int j = 80;
//  KAKO DA UCITAM BLCK_SIZE IZ MAIN FUNKCIJE???
  while(j--)
  {
    int i = 0;
    for(;i<BLCK_SIZE;++i)
    {
      *((int*)p+i) = i;
    }
    if(j%20==0)
    {
      sem_post(&sema);
      sem_wait(&sema1);
    }
  }
  return 0;
}

int main ()
{
  sem_init(&sema,0,0);
  sem_init(&sema1,0,0);
  int BLCK_SIZE;
  printf("Unesite vrednost memorije za alokaciju u MB:");
  BLCK_SIZE = memparse ();
  int* mem = calloc(4,BLCK_SIZE*sizeof(int));
  if(!mem)
  {
    printf("not enough memory\n");
    return 0;
  }
  pthread_t tid[4];

  pthread_create(tid+0,0,tf,mem+0*BLCK_SIZE);
  pthread_create(tid+1,0,tf,mem+0*BLCK_SIZE);
  pthread_create(tid+2,0,tf,mem+0*BLCK_SIZE);
  pthread_create(tid+3,0,tf,mem+0*BLCK_SIZE);

  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf ("25 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("50 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("75 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("100 percent done - Test completed!\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  pthread_join(tid[0],NULL);
  pthread_join(tid[1],NULL);
  pthread_join(tid[2],NULL);
  pthread_join(tid[3],NULL);

  free(mem);
  sem_destroy(&sema);
  sem_destroy(&sema1);

  return 0;
}


Eto pitanje je u samom kodu :D
KAKO DA UCITAM BLCK_SIZE IZ MAIN FUNKCIJE U TF FUNKCIJU *(:()
make love - !war
 
Odgovor na temu

k0m1kku

Član broj: 194551
Poruke: 1
*.adsl.beotel.net.



Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 19:58 - pre 188 meseci
2 x Intel(R) Xeon(TM) CPU 3.00GHz
Motherboard Intel S5000PAL

Citat:
real 0m4.051s
user 0m4.050s
sys 0m0.001s
 
Odgovor na temu

Branimir Maksimovic

Član broj: 64947
Poruke: 5534
c-bg-d-p6-36.bvcom.net.



+1064 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 20:13 - pre 188 meseci
combuster, samo stavi definiciju BLOCK_SIZE-a na pocetak tj kod semafora da bude globalna, bice dovoljno ;)

Pozdrav!
 
Odgovor na temu

combuster
Ivan Bulatovic
Kraljevo

Član broj: 151351
Poruke: 4563
79.101.165.*

Sajt: www.linuxsrbija.org


+104 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 22:22 - pre 188 meseci
Code:

#include <stdlib.h>
#include <semaphore.h>
#include <pthread.h>
#include <stdio.h>

sem_t sema,sema1;
int BLCK_SIZE;

int memparse ();
int memload ();

int memparse()
{
  int d;
  int i;
  i = memload ();
  d = i * 65536;
  return d;
}

int memload()
{
  int memory;
  scanf("%d", &memory);
  return memory;
}

void* tf(void* p)
{
  int j = 80;
  while(j--)
  {
    int i = 0;
    for(;i<BLCK_SIZE;++i)
    {
      *((int*)p+i) = i;
    }
    if(j%20==0)
    {
      sem_post(&sema);
      sem_wait(&sema1);
    }
  }
  return 0;
}

int main ()
{
  sem_init(&sema,0,0);
  sem_init(&sema1,0,0);
  int mb;
  printf("Unesite vrednost memorije za alokaciju u MB:");
  BLCK_SIZE = memparse ();
  mb = 0.000015259 * BLCK_SIZE;
  int* mem = calloc(4,BLCK_SIZE*sizeof(int));
  if(!mem)
  {
    printf("not enough memory\n");
    return 0;
  }
  else printf("program allocated %d MB of RAM\n", mb);

  pthread_t tid[4];

  pthread_create(tid+0,0,tf,mem+0*BLCK_SIZE);
  pthread_create(tid+1,0,tf,mem+0*BLCK_SIZE);
  pthread_create(tid+2,0,tf,mem+0*BLCK_SIZE);
  pthread_create(tid+3,0,tf,mem+0*BLCK_SIZE);

  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf ("25 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("50 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("75 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("100 percent done - Test completed!\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  pthread_join(tid[0],NULL);
  pthread_join(tid[1],NULL);
  pthread_join(tid[2],NULL);
  pthread_join(tid[3],NULL);

  free(mem);
  sem_destroy(&sema);
  sem_destroy(&sema1);

  return 0;
}


Hvala Branimire, hvala, e sad jos samo da integrisemo merenje vremena u kodu, ja mislim da ima jedan header koji sadrzi funkcije za rad sa vremenom, provericemo...
Inace sada program pita korisnika koliko ram-a da alocira (radi provereno)...
make love - !war
 
Odgovor na temu

Srđan Pavlović
Specijalna Edukacija i Rehabilitacija MNRO
Vojvodina, Bačka Palanka

Član broj: 139340
Poruke: 5571
93.86.118.*

Sajt: www.oligofrenolog.com


+382 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 22:37 - pre 188 meseci
Ovaj kod kod mene se zaglavi ako stavim manje od 20 (stane na 75%) i moram Ctrl-C.

Sa 19 mi zaglavi (MB), ako stavim 20 i vise, onda prolazi.
 
Odgovor na temu

combuster
Ivan Bulatovic
Kraljevo

Član broj: 151351
Poruke: 4563
79.101.165.*

Sajt: www.linuxsrbija.org


+104 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 22:54 - pre 188 meseci
Ovo je sad islo mnogo lakse... Sada meri i vreme...

Code:

#include <stdlib.h>
#include <semaphore.h>
#include <pthread.h>
#include <stdio.h>
#include <time.h>

time_t timer1,timer2;
struct tm *tarray1,*tarray2;
sem_t sema,sema1;
int BLCK_SIZE;

int memparse ();
int memload ();

int memparse()
{
  int d;
  int i;
  i = memload ();
  d = i * 65536;
  return d;
}

int memload()
{
  int memory;
  scanf("%d", &memory);
  return memory;
}

void* tf(void* p)
{
  int j = 80;
  while(j--)
  {
    int i = 0;
    for(;i<BLCK_SIZE;++i)
    {
      *((int*)p+i) = i;
    }
    if(j%20==0)
    {
      sem_post(&sema);
      sem_wait(&sema1);
    }
  }
  return 0;
}

int main ()
{
  int min1, sec1, min2, sec2;
  timer1 = time(NULL);
  tarray1 = localtime(&timer1);
  min1 = tarray1->tm_min;
  sec1 = tarray1->tm_sec;  
  sem_init(&sema,0,0);
  sem_init(&sema1,0,0);
  int mb;
  printf("Enter the amount of memory to be allocated in MB:");
  BLCK_SIZE = memparse ();
  mb = 0.000015259 * BLCK_SIZE;
  int* mem = calloc(4,BLCK_SIZE*sizeof(int));
  if(!mem)
  {
    printf("not enough memory\n");
    return 0;
  }
  else printf("program allocated %d MB of RAM\n", mb);

  pthread_t tid[4];

  pthread_create(tid+0,0,tf,mem+0*BLCK_SIZE);
  pthread_create(tid+1,0,tf,mem+0*BLCK_SIZE);
  pthread_create(tid+2,0,tf,mem+0*BLCK_SIZE);
  pthread_create(tid+3,0,tf,mem+0*BLCK_SIZE);

  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf ("25 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("50 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("75 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("100 percent done - Test completed!\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  pthread_join(tid[0],NULL);
  pthread_join(tid[1],NULL);
  pthread_join(tid[2],NULL);
  pthread_join(tid[3],NULL);

  free(mem);
  sem_destroy(&sema);
  sem_destroy(&sema1);
  timer2 = time(NULL);
  tarray2 = localtime(&timer2);
  min2 = tarray2->tm_min;
  sec2 = tarray2->tm_sec;
  printf ("Time of execution is %d min : %d sec\n", min2-min1,sec2-sec1);
  return 0;
}


Cheers 4 branimir, kernel-1, jbyn4e, lil' o me and everyone that tested this peace of code... :D
make love - !war
 
Odgovor na temu

Srđan Pavlović
Specijalna Edukacija i Rehabilitacija MNRO
Vojvodina, Bačka Palanka

Član broj: 139340
Poruke: 5571
93.86.118.*

Sajt: www.oligofrenolog.com


+382 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 23:00 - pre 188 meseci
radi, samo sa vise MB, sad mi je zakucao na 75% i na 30mb....
...vreme meri OK, ako moze stotinke da se mere jos bolje, samo sekunde su malo grube za ovaj sport ;)

(jbt, ja samo narucujem) ;)
 
Odgovor na temu

combuster
Ivan Bulatovic
Kraljevo

Član broj: 151351
Poruke: 4563
79.101.165.*

Sajt: www.linuxsrbija.org


+104 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 23:04 - pre 188 meseci
Da, zeza sa manje MB, sumnjam na semaforcice ali ne mora da znaci... Ohoho jos jedna greska, hehehehe izlazi mi -9 sec sto znaci da moram da stavim ovo kao apsolutnu vrednost... lupetam, samo treba sekunde da oduzmem i ostatak na minute :D, opet lupetam, parsujem vrednost time-a... Moram da razmislim malo...
make love - !war
 
Odgovor na temu

combuster
Ivan Bulatovic
Kraljevo

Član broj: 151351
Poruke: 4563
79.101.165.*

Sajt: www.linuxsrbija.org


+104 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 23:32 - pre 188 meseci
Evo ga ljudi konacno finito... Problem sa alociranjem MB-a ostaje ali je merenje vremena ispravljeno. Sad i ako ga pokrenete ko sto kaze nas narod u minut do 12 radice ispravno... :D Evo ga RC:

Code:

#include <stdlib.h>
#include <semaphore.h>
#include <pthread.h>
#include <stdio.h>
#include <time.h>

time_t timer1,timer2;
struct tm *tarray1,*tarray2;
sem_t sema,sema1;
int BLCK_SIZE;

int memparse ();
int memload ();

int memparse()
{
  int d;
  int i;
  i = memload ();
  d = i * 65536;
  return d;
}

int memload()
{
  int memory;
  scanf("%d", &memory);
  return memory;
}

void* tf(void* p)
{
  int j = 80;
  while(j--)
  {
    int i = 0;
    for(;i<BLCK_SIZE;++i)
    {
      *((int*)p+i) = i;
    }
    if(j%20==0)
    {
      sem_post(&sema);
      sem_wait(&sema1);
    }
  }
  return 0;
}

int main ()
{
  int min1,min2,sec1,sec2,minf,secf;
  timer1 = time(NULL);
  tarray1 = localtime(&timer1);
  min1 = tarray1->tm_min;
  sec1 = tarray1->tm_sec;  
  sem_init(&sema,0,0);
  sem_init(&sema1,0,0);
  int mb;
  printf("Enter the amount of memory to allocate in MB:");
  BLCK_SIZE = memparse ();
  mb = 0.000015259 * BLCK_SIZE;
  int* mem = calloc(4,BLCK_SIZE*sizeof(int));
  if(!mem)
  {
    printf("not enough memory\n");
    return 0;
  }
  else printf("program allocated %d MB of RAM\n", mb);

  pthread_t tid[4];

  pthread_create(tid+0,0,tf,mem+0*BLCK_SIZE);
  pthread_create(tid+1,0,tf,mem+1*BLCK_SIZE);
  pthread_create(tid+2,0,tf,mem+2*BLCK_SIZE);
  pthread_create(tid+3,0,tf,mem+3*BLCK_SIZE);

  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf ("25 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("50 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("75 percent done:\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf("100 percent done - Test completed!\n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  pthread_join(tid[0],NULL);
  pthread_join(tid[1],NULL);
  pthread_join(tid[2],NULL);
  pthread_join(tid[3],NULL);

  timer2 = time(NULL);
  tarray2 = localtime(&timer2);
  min2 = tarray2->tm_min;
  sec2 = tarray2->tm_sec;
  if (min2 < min1) 
{
  minf = min2 + 60 - min1;
}
  else 
  minf = min2 - min1;
  
  if (sec2 < sec1) 
{
  secf = sec2 + 60 - sec1;
  minf -= 1;
}  
  else
  secf = sec2 - sec1;
  printf ("Time of execution is %d min : %d sec\n",minf,secf);
  free(mem);
  sem_destroy(&sema);
  sem_destroy(&sema1);
  return 0;
}


EVO SAD SVE RADI !!! Izmenjeno, ja sam napravio bug u izmenama u pthread-ovima, pokusavao sam da prosledim BLCK_SIZE funkciji tf kao atribut ali pthread_create moze da prosledi samo jedan argument i onda sam tu vracao nesto i bilo je mem+0*BLCK_SIZE na sva cetiri thread-a umesto da inkrementira za 1...

Moze se reci da je ovo sad final release...

[Ovu poruku je menjao combuster dana 07.11.2008. u 01:06 GMT+1]
make love - !war
 
Odgovor na temu

Srđan Pavlović
Specijalna Edukacija i Rehabilitacija MNRO
Vojvodina, Bačka Palanka

Član broj: 139340
Poruke: 5571
93.86.118.*

Sajt: www.oligofrenolog.com


+382 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"06.11.2008. u 23:40 - pre 188 meseci
srdjan@Zverko:~$ ./test-2-run
Unesite vrednost memorije za alokaciju u MB:4096
program allocated 4096 MB of RAM
25 percent done:
50 percent done:
75 percent done:
100 percent done - Test completed!
Time of execution is 2 min : 17 sec
srdjan@Zverko:~$


Zauzece se cudno ponasa... recimo pise da imam free 3348MB trenutno.
Pustim test sa 348mb, i dok radi, pise 3260mb free (tako nesto), ili kada
stavim 1024 mb, pise da tokom rada testa zauzima samo oko 280mb rama... nesto se tu optimizuje, ili se ne alocira dobro.

[Ovu poruku je menjao Kernel-1 dana 07.11.2008. u 00:56 GMT+1]

/edit: provera fixed coda.. :)

[Ovu poruku je menjao Kernel-1 dana 07.11.2008. u 01:04 GMT+1]

/edit: Sada radi OK, imao sam 3346mb free, zadao mu 346, tokom rada 3000mb mem free - bravo :)

[Ovu poruku je menjao Kernel-1 dana 07.11.2008. u 01:07 GMT+1]
 
Odgovor na temu

Srđan Pavlović
Specijalna Edukacija i Rehabilitacija MNRO
Vojvodina, Bačka Palanka

Član broj: 139340
Poruke: 5571
93.86.118.*

Sajt: www.oligofrenolog.com


+382 Profil

icon Re: Test Brzine procesora - "besposlen pop jarice krsti"07.11.2008. u 01:14 - pre 188 meseci
Evo i prevedene verzije, i dodao sam samo ogranicenja za min i max mem unos, ostaje pitanje zasto program ne radi sa nizim vrednostima unosa (oko 30 i nize),
i da se implementira preciznije merenje vremena (bar stotinke):

Code:

#include <stdlib.h>
#include <semaphore.h>
#include <pthread.h>
#include <stdio.h>
#include <time.h>

time_t timer1,timer2;
struct tm *tarray1,*tarray2;
sem_t sema,sema1;
int BLCK_SIZE;

int memparse ();
int memload ();

int memparse()
{
  int d;
  int i;
  i = memload ();
  d = i * 65536;
  return d;
}

int memload()
{
  int memory;
  scanf("%d", &memory);
  return memory;
}

void* tf(void* p)
{
  int j = 80;
  while(j--)
  {
    int i = 0;
    for(;i<BLCK_SIZE;++i)
    {
      *((int*)p+i) = i;
    }
    if(j%20==0)
    {
      sem_post(&sema);
      sem_wait(&sema1);
    }
  }
  return 0;
}

int main ()
{
  int min1,min2,sec1,sec2,minf,secf;
  timer1 = time(NULL);
  tarray1 = localtime(&timer1);
  min1 = tarray1->tm_min;
  sec1 = tarray1->tm_sec;  
  sem_init(&sema,0,0);
  sem_init(&sema1,0,0);
  int mb;
  printf ("\n"); 
  printf("Unesite koliko memorije alocirate za test (64 do 512 MB):");
  BLCK_SIZE = memparse ();
  mb = 0.000015259 * BLCK_SIZE;
  int* mem = calloc(4,BLCK_SIZE*sizeof(int));

  if (mb < 64) 
{
printf("\n"); 
printf("Postavljena vrednost nije dozvoljena.\n"); 
printf("\n");
return 0;
}

if (mb > 512)
{
printf("\n");
printf("Postavljena vrednost nije dozvoljena.\n"); 
printf("\n");
return 0;
}

  
  if(!mem)
  {
    printf("Nema dovoljno memorije.\n");
    return 0;
  }
  else printf("Program je alocirao %d MB RAM-a.\n", mb);

  pthread_t tid[4];

  pthread_create(tid+0,0,tf,mem+0*BLCK_SIZE);
  pthread_create(tid+1,0,tf,mem+1*BLCK_SIZE);
  pthread_create(tid+2,0,tf,mem+2*BLCK_SIZE);
  pthread_create(tid+3,0,tf,mem+3*BLCK_SIZE);

  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf ("25 procenata komletirano... \n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf ("50 procenata komletirano... \n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf ("75 procenata komletirano... \n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  sem_wait(&sema);
  printf ("100 procenata komletirano! \n");
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  sem_post(&sema1);
  
  pthread_join(tid[0],NULL);
  pthread_join(tid[1],NULL);
  pthread_join(tid[2],NULL);
  pthread_join(tid[3],NULL);

  timer2 = time(NULL);
  tarray2 = localtime(&timer2);
  min2 = tarray2->tm_min;
  sec2 = tarray2->tm_sec;
  if (min2 < min1) 
{
  minf = min2 + 60 - min1;
}
  else 
  minf = min2 - min1;
  
  if (sec2 < sec1) 
{
  secf = sec2 + 60 - sec1;
  minf -= 1;
}  
  else
  secf = sec2 - sec1;
  printf ("\n");
  printf ("Vreme izvrsavanja je %d minuta i %d sekundi.\n",minf,secf);
  printf ("\n");
  free(mem);
  sem_destroy(&sema);
  sem_destroy(&sema1);
  return 0;
}


U attachment-u je izvrsna verzija ovoga za 64-bit sistem, program se vise ne mora startovati sa "time" (10x to combuster) :)

Interesantno je pratiti i krivulju rasta potrebnog vremena kada se kolicina memorije uduplava:

Na mom racunaru izgleda ovako: 64mb --> 4 sekunde, 128mb --> 10 sekundi, 256mb --> 14 sekundi, 512mb --> 20 sekundi.

/edit: btw, jel ima neko eeeAsus-a za probu? :D

[Ovu poruku je menjao Kernel-1 dana 07.11.2008. u 06:13 GMT+1]
Prikačeni fajlovi
 
Odgovor na temu

[es] :: Linux aplikacije :: Test Brzine procesora - "besposlen pop jarice krsti"

Strane: < .. 1 2 3 4 5 6

[ Pregleda: 26516 | Odgovora: 119 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.