Skip to content
Snippets Groups Projects
Commit a061285a authored by LITIERE MALRIC's avatar LITIERE MALRIC
Browse files

debut du TP2

parent a773fcae
Branches
No related merge requests found
......@@ -10,7 +10,7 @@ int main() {
printf("Tri Insertion: \n");
long* triIns = malloc(sizeof(long) * taille);
listeAlea(triIns,100,300);
affichertab(triIns,100);
affichertab(triIns,100);
triInsertion(triIns,100);
affichertab(triIns,100);
......
all: main
main : tris.o main.c
gcc -o main -Wall utils.o -g main.c
tris.o : tris.c tris.h
gcc -c -Wall -g tris.c
clean :
rm *.o
# P4z : Analyse de performances de différents tris
## Problème
Trouver quelle est l'algorithme de trie le plus efficace sur un tableau trié et sur un tableau non trié.
```
- Le temps d'éxécution d'un tri (Sur les tableaux de differentes allures)
- La consommation de memoire lors du tri (Sur les tableaux de differentes allures)
- Son estimation de temps d'execution (La fonction O(f) -> log(n), n^2, nlog(n), etc)
- Pareil pour la memoire
- Le nombre de comparaisons total
- Le nombre d'ecritures total
```
## Dispositif expérimental
### Application
[Main](./main.c)
```
main --taille --typeTableau --typeTri
```
| Arguments | Default | Description |
| :------------------------ |:-------------:| :-------------|
| `--taille` | **1000** | **La taille du tableau de n éléments.** |
| `--typeTableau -aricm` | **a** | **Défini le type du tableau avec `a` aléatoire, `t` trié, `i` inversé, `c` identique et `m` trié à moitié.**|
| `--typeTri -irf` | **i** | **Algorithme de tri avec `i` insertion, `r` rapide et `f` fusion.** |
### Environnement de test
Nos test sont réalisé sur le serveur Phoenix avec comme caractéristique
```
Processeur(s) : 40
Liste de processeur(s) en ligne : 0-39
Thread(s) par cœur : 2
Cœur(s) par socket : 10
Socket(s) : 2
Nom de modèle : Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz
Vitesse maximale du processeur en MHz : 3100,0000
Cache L1d : 32K
Cache L1i : 32K
Cache L2 : 256K
Cache L3 : 25600K
```
### Description de la démarche systématique
Description de la démarche systématique et de l'espace d'exploration pour chaque paramètres.
```
Suite des commandes, ou script, à exécuter pour produire les données.
```
## Résultats préalables
### Temps d'exécution
| Jeu de test | Tri par Insertion | Tri Fusion | Tri Rapide |
|----------------------|---------------------------|---------------------------|---------------------------|
| Aléatoire | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
| Trié | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
| Tri inversé | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
### Consommation mémoire
| Jeu de test | Tri par Insertion | Tri Fusion | Tri Rapide |
|----------------------|---------------------------|---------------------------|---------------------------|
| Aléatoire | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
| Trié | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
| Tri inversé | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
### Analyse des résultats préalables
Explications précises et succinctes des résultats préalables.
### Discussion des résultats préalables
Explications précises et succinctes des limites des résultats
préalables et ce qu'ils ne permettent pas de vérifier.
## Etude approfondie
### Hypothèse
Expression précise et succincte d'une hypothèse.
### Protocole expérimental de vérification de l'hypothèse
Expression précise et succincte du protocole.
```
Suite des commandes, ou script, à exécuter pour produire les données.
```
### Résultats expérimentaux
### Analyse des résultats expérimentaux
### Discussion des résultats expérimentaux
## Conclusion et travaux futurs
#include <stdio.h>
#include <stdlib.h>
#include "tris.h"
#include "utils.h"
int main(int argc, char *argv[])
{
if (argc != 4)
{
printf("Usage: %s [taille] [typeTableau] [typeAlgo]\n", argv[0]);
exit(1);
}
long taille = (long)atoi(argv[1]);
char typeTable = argv[2][0];
char typeAlgo = argv[3][0];
long *tab = malloc(sizeof(long) * taille);
long MAX = 200;
gentable(tab, taille, typeTable, MAX);
switch (typeAlgo)
{
case 'i':
triInsertion(tab, taille);
break;
case 'r':
triRapide(tab, taille, versionRap);
break;
case 'f':
triFusion(tab, taille);
break;
}
free(tab);
return 0;
}
\ No newline at end of file
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "tris.h"
void triInsertion(long* A, size_t n) {
for(size_t i = 1; i <= n-1; i++){
long cle = A[i];
size_t j = i - 1;
while(j+1 >= j && A[j] > cle){
A[j+1] = A[j];
j = j-1;
}
A[j+1] = cle;
}
}
void triFusion(long* A, size_t n) {
sousTriFusion(A, 0, n);
}
void sousTriFusion(long* A, size_t first, size_t n) {
if(first+1 <n){ // p < r - 1
size_t middle = floor((first+n)/2);
sousTriFusion(A, first, middle);
sousTriFusion(A, middle, n);
fusion(A, first, middle, n);
}
}
void copySousTable(long* mainT, long* underT, size_t id, size_t n) {
for(size_t i = id; i < id+n; ++i) {
underT[i-id] = mainT[i];
}
}
void fusion(long* A, size_t first, size_t middle, size_t n) {
size_t n1 = middle - first; // Nb elem dans A[p , q] q exclu
size_t n2 = n - middle; // Nb elem dans A[q , r] r exclu
size_t indg = 0;
size_t indd = 0;
long* ag = malloc(sizeof(long) * n1);
long* ad = malloc(sizeof(long) * n2);
copySousTable(A, ag, first, n1);
copySousTable(A, ad, middle, n2);
int i = first;
while(i < n) {
if(indg == n1) {
A[i] = ad[indd];
indd++;
}
else if(indd == n2) {
A[i] = ag[indg];
indg++;
}
else if(ag[indg] < ad[indd]) {
A[i] = ag[indg];
indg++;
}
else {
A[i] = ad[indd];
indd++;
}
++i;
}
free(ag);
free(ad);
}
void triRapide(long* A, size_t n) {
sousTriRapide(A,0,n);
}
void sousTriRapide(long* A, size_t first, size_t n){
if(first+1 < n){
size_t middle = partition(A,first,n);
sousTriRapide(A,first,middle);
sousTriRapide(A,middle+1,n);
}
}
size_t partition(long* A, size_t first, size_t n) {
long pivot = A[n-1];
size_t i = first;
for(int j = first; j+2 <= n; j++){
if(A[j] <= pivot){
permuter(A,i,j);
i++;
}
}
permuter(A,i,n-1);
return i;
}
void permuter(long* A,size_t i,size_t j) {
long inter = A[i];
A[i] = A[j];
A[j] = inter;
}
#ifndef TRIS_H
#define TRIS_H
#include <stdint.h>
#include <stdlib.h>
void triInsertion(long* A, size_t n);
void triFusion(long* A, size_t size);
void sousTriFusion(long* A, size_t first, size_t size);
void fusion(long* A, size_t first, size_t middle, size_t size);
void triRapide(long* A, size_t n);
void sousTriRapide(long* A, size_t first, size_t size);
size_t partition(long* A, size_t first, size_t size);
void permuter(long* A,size_t i,size_t j);
#endif //TRIS_H
#include <stdio.h>
#include <stdlib.h>
#include "utils.h"
void affichertab(long *T, int s)
{
printf("[ ");
for (int i = 0; i < s - 1; i++)
{
printf("%ld , ", T[i]);
}
printf("%ld ]\n", T[s - 1]);
}
void genTable(long *T, long taille, char type, long N)
{
int mid = (int)(taille / 2);
switch (type)
{
case 'a':
//Tableau Aleatoire
for (long i = 0; i < taille; ++i)
{
T[i] = rand() % N;
}
break;
case 'r':
//Tableau Rangé
for (long i = 0; i < taille; ++i)
{
T[i] = i;
}
break;
case 'i':
//Tableau Rangé Inversé
for (long i = 0; i < taille; ++i)
{
T[i] = taille - i;
}
break;
case 'c':
//Tableau Constant
for (long i = 0; i < taille; ++i)
{
T[i] = 1;
}
break;
case 'm':
//Tableau Trie a moitie
for (long i = 0; i < mid; ++i)
{
T[i] = i;
}
for (long i = mid; i < taille; ++i)
{
T[i] = rand() % N;
}
break;
default:
break;
}
}
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
void affichertab(long* T, int s);
void genTable(long *T, long taille, char type, long N);
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment