-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
i=0 | ||
while [ $i -lt $1 ] | ||
do | ||
/usr/bin/time nice ./fib 45& | ||
i=`expr $i + 1` #incrementa en 1 la variable i | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
if [ "$#" -ne 1 ] | ||
then | ||
echo "usage $0 num" | ||
echo "num: numero de procesos fibonacci a ejecutar en paralelo" | ||
exit | ||
fi | ||
|
||
echo $1 | ||
|
||
i=0 | ||
while [ $i -lt $1 ] | ||
do | ||
/usr/bin/time ./fib 45& | ||
i=`expr $i + 1` | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
all:fibonacci mem1 | ||
|
||
fibonacci:fibonacci.c | ||
gcc -o fib fibonacci.c | ||
|
||
mem1:mem1.c | ||
gcc -o mem1 mem1.c | ||
|
||
clean: | ||
rm -f fib mem1 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
long fibonacci(unsigned i) { | ||
if (i == 0) return 0; | ||
if (i == 1) return 1; | ||
return fibonacci(i-1) + fibonacci(i-2); | ||
} | ||
|
||
void usage() { | ||
char buffer[80]; | ||
|
||
strcpy(buffer,"fib n\n"); | ||
write(1,buffer,strlen(buffer)); | ||
exit(1); | ||
} | ||
void main(int argc,char *argv[]) { | ||
unsigned n; | ||
long f; | ||
char buffer[80]; | ||
|
||
if (argc != 2) usage(); | ||
n = atoi(argv[1]); | ||
f = fibonacci(n); | ||
sprintf(buffer,"El fibonacci de %u es %ld\n",n,f); | ||
write(1, buffer, strlen(buffer)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
|
||
#define REGION_SIZE 256*1024*1024 | ||
|
||
/* | ||
* rdtsc is an assembler instruction that get the cycles executed by the processor since boot time. | ||
*/ | ||
#define getCycles(low,high) __asm__ __volatile__("rdtsc": "=a"(low), "=d"(high)) | ||
|
||
static inline unsigned long long getTime(void) | ||
{ | ||
unsigned long low, high; | ||
getCycles(low, high); | ||
return ((unsigned long long)high << 32) + low; | ||
|
||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int i, j; | ||
int *p; | ||
unsigned long long initTime; | ||
unsigned long long endTime; | ||
long long region_size; | ||
int nelts; | ||
int nits; | ||
int nprocs; | ||
int ret; | ||
char buff[256]; | ||
|
||
if (argc != 4) { | ||
sprintf( buff, "usage: mem2_4 region_size processes iterations \n"); | ||
write(1, buff, strlen(buff)); | ||
exit(1); | ||
} | ||
|
||
region_size = atoll(argv[1]); | ||
nprocs = atoi(argv[2]); | ||
nits = atoi(argv[3]); | ||
|
||
// compute the number of integers that fits in the region | ||
nelts = region_size / sizeof(int); | ||
|
||
//loop to create the number of processes required | ||
i = 1; | ||
ret = 1; | ||
while ((i < nprocs) && (ret > 0)) { | ||
ret = fork(); | ||
i++; | ||
} | ||
|
||
//code that executes each process | ||
p = malloc(region_size); | ||
if (p == NULL) { | ||
sprintf( buff, "Unable to allocate the memory region\n"); | ||
write(1, buff, strlen(buff)); | ||
exit(1); | ||
} | ||
//loop to control how many times each process accesses all the elements of the vector | ||
i = 0; | ||
while (i < nits) { | ||
initTime = getTime(); | ||
//loop to access all the elements in the vector | ||
for (j = 0; j < nelts; j++) | ||
p[j] = j; | ||
endTime = getTime(); | ||
sprintf( buff, "process: %d, iteration %d, access loop time: %llu\n", | ||
getpid(), i, (endTime - initTime)); | ||
write(1, buff, strlen(buff)); | ||
i++; | ||
|
||
} | ||
sprintf( buff, "Entering endless loop\n"); | ||
write(1, buff, strlen(buff)); | ||
while (1) ; | ||
} |