Anda di halaman 1dari 4

# Algoritma Shuffle Exchange (SIMD Perfect Shuffle)

## Menggunakan Bahasa C dengan Compiler GCC

pada Sistem Operasi Linux Ubuntu 12.04

Disusun oleh
1. Pebi Yudha K.
2. Suratmin
3. Anggun Hariawan

2A111278
2A113146
2A113068

## Kode Program Selengkapnya: shuffle-exchange.c

/*******************************************************************************
*
*
*
Algoritma Shuffle Exchange
*
*
Hak Cipta (C) Pebi Yudha K. - 2013
*
*
*
*
*
*
*
******************************************************************************/
#include
#include
#include
#include

<math.h>
<stdio.h>
<stdlib.h>
<time.h>

## typedef unsigned short int USHORT;

void shuffle(USHORT banyak_prosesor, int *prosesor, int *dummy);
void exchange(USHORT banyak_prosesor, int *prosesor, int *dummy);
int main(void)
{
USHORT n_prosesor, indeks;
float log_n;
clock_t t;
int prosesor[256], dummy_prosesor[256];
for (;;)
{
printf("\nTentukan banyak prosesor (integer maks. 256) : ");
scanf("%hu", &n_prosesor);
if ((n_prosesor > 0) && (n_prosesor <= 256)) break;
}
printf("\nMasukan data untuk setiap prosesor\n");
for (indeks = 0; indeks < n_prosesor; indeks++)
{
printf("Data untuk prosesor %d: ", indeks + 1);
scanf("%d", &prosesor[indeks]);
}
printf("\nData di setiap prosesor\n");
for (indeks = 0; indeks < n_prosesor; indeks++)
printf("%d\t", prosesor[indeks]);
log_n = log10(n_prosesor) / log10(2);
for (indeks = 1; indeks <= log_n; indeks++)
{
printf("\nIterasi ke-%d\n", indeks);
t = clock();
shuffle(n_prosesor, prosesor, dummy_prosesor);

## exchange(n_prosesor, prosesor, dummy_prosesor);

t = clock() - t;
printf("\nWaktu proses %f s\n", ((double) t) / CLOCKS_PER_SEC);
}
printf("\n");
return EXIT_SUCCESS;
}
void shuffle(USHORT banyak_prosesor, int *prosesor, int *dummy)
{
USHORT indeks, j, tengah;
tengah = (banyak_prosesor / 2) - 1;
for (indeks = 0; indeks < banyak_prosesor; indeks++)
{
if ((indeks >= 0) && (indeks <= tengah))
j = 2 * indeks;
else
j = (2 * indeks) + 1 - banyak_prosesor;
dummy[indeks] = prosesor[j];
}
for (indeks = 0; indeks < banyak_prosesor; indeks++)
{
prosesor[indeks] = dummy[indeks];
printf("%d\t", dummy[indeks]);
}
return;
}
void exchange(USHORT banyak_prosesor, int *prosesor, int *dummy)
{
USHORT indeks;
int temp;
printf("\n");
for (indeks = 0; indeks < banyak_prosesor; (indeks += 2))
{
dummy[indeks] = prosesor[indeks + 1];
dummy[indeks + 1] = prosesor[indeks];
}
for (indeks = 0; indeks < banyak_prosesor; indeks++)
printf("%d\t", dummy[indeks]);
printf("\n");
for (indeks = 0; indeks < banyak_prosesor; indeks++)
{
prosesor[indeks] += dummy[indeks];
printf("%d\t", prosesor[indeks]);
}

return;
}

## Tampilan Input/Output dengan Input 16 Prosesor

### Dapatkan aplikasi gratis kami

Hak cipta © 2021 Scribd Inc.