From f65583b5d0b7dc985ac7256909ad700f15536a55 Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 31 Oct 2024 12:40:28 +0100 Subject: [PATCH 1/2] cambios 2024-10-31 12:40:28 --- .obsidian/workspace.json | 111 +++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 63 deletions(-) diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index a66ea3a..2d5c187 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -4,36 +4,20 @@ "type": "split", "children": [ { - "id": "c841a021395cc4d3", + "id": "90d0925ab4ee2d0c", "type": "tabs", "children": [ { - "id": "d8a559569207f8b1", + "id": "3b843e69b2a87354", "type": "leaf", "state": { - "type": "image", - "state": { - "file": "TERCERO/SPD/images/Pasted image 20241022150214.png" - }, - "icon": "lucide-image", - "title": "Pasted image 20241022150214" - } - }, - { - "id": "2cf8494471daa0d9", - "type": "leaf", - "state": { - "type": "diff-view", - "state": { - "file": "conflict-files-obsidian-git.md", - "staged": false - }, - "icon": "git-pull-request", - "title": "Diff View (conflict-files-obsidian-git)" + "type": "empty", + "state": {}, + "icon": "lucide-file", + "title": "New tab" } } - ], - "currentTab": 1 + ] } ], "direction": "vertical" @@ -89,7 +73,7 @@ } ], "direction": "horizontal", - "width": 300 + "width": 392.5 }, "right": { "id": "44cf06183e1c1c7d", @@ -105,7 +89,7 @@ "state": { "type": "backlink", "state": { - "file": "TERCERO/SS/SS 24-25.md", + "file": "TERCERO/ATR1/Teoría_2425.md", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -115,7 +99,7 @@ "unlinkedCollapsed": true }, "icon": "links-coming-in", - "title": "Backlinks for SS 24-25" + "title": "Backlinks for Teoría_2425" } }, { @@ -124,12 +108,12 @@ "state": { "type": "outgoing-link", "state": { - "file": "TERCERO/SS/SS 24-25.md", + "file": "TERCERO/ATR1/Teoría_2425.md", "linksCollapsed": false, "unlinkedCollapsed": true }, "icon": "links-going-out", - "title": "Outgoing links from SS 24-25" + "title": "Outgoing links from Teoría_2425" } }, { @@ -151,10 +135,10 @@ "state": { "type": "outline", "state": { - "file": "TERCERO/SS/SS 24-25.md" + "file": "TERCERO/ATR1/Teoría_2425.md" }, "icon": "lucide-list", - "title": "Outline of SS 24-25" + "title": "Outline of Teoría_2425" } }, { @@ -183,56 +167,57 @@ "templates:Insert template": false, "command-palette:Open command palette": false, "table-editor-obsidian:Advanced Tables Toolbar": false, - "obsidian-git:Open Git source control": false + "obsidian-git:Open Git source control": false, + "obsidian-advanced-slides:Show Slide Preview": false } }, - "active": "2cf8494471daa0d9", + "active": "b40a18c39aef8e17", "lastOpenFiles": [ - "conflict-files-obsidian-git.md", - "TERCERO/SPD/images/Pasted image 20241022150214.png", - "TERCERO/ATR1/images/Pasted image 20241020204947.png", - "TERCERO/ATR1/images/Pasted image 20241020204701.png", - "TERCERO/ATR1/images/Pasted image 20241020204340.png", - "TERCERO/ATR1/images/Pasted image 20241020204107.png", - "TERCERO/SPD/P4_SPD.md", - "TERCERO/SPD/images/Pasted image 20241022144832.png", - "TERCERO/SPD/images/Pasted image 20241022144429.png", "TERCERO/SPD/Teoría_2425.md", + "TERCERO/SPD/Guión Practica 4 SPD.md", + "TERCERO/SPD/P4_SPD_Presentacion.md", + "TERCERO/SPD/images/Pasted image 20241022144832.png", + "TERCERO/SPD/images/Pasted image 20241022150214.png", + "TERCERO/SPD/P4_SPD.md", + "TERCERO/SPD/images/Pasted image 20241022144429.png", "TERCERO/SPD/images/Pasted image 20241022134454.png", - "Imagen de WhatsApp 2024-10-22 a las 11.43.21_270060da.jpg", - "TERCERO/IA/images/tic-tac-toe.gif", - "TERCERO/IA/Teoría_2425.md", + "TERCERO/SPD/images/Pasted image 20240930084659.png", + "TERCERO/SPD/images/Pasted image 20240916121903.png", + "export/P4_SPD_Presentacion/plugin/chalkboard/img/whiteboard.png", + "export/P4_SPD_Presentacion/plugin/chalkboard/img/chalk-yellow.png", + "export/P4_SPD_Presentacion/plugin/chalkboard/img/sponge.png", + "export/P4_SPD_Presentacion/plugin/chalkboard/img/chalk-white.png", + "export/P4_SPD_Presentacion/plugin/chalkboard/style.css", + "export/P4_SPD_Presentacion/plugin/chalkboard/_style.css", + "export/P4_SPD_Presentacion/plugin/chalkboard/plugin.js", + "export/P4_SPD_Presentacion/plugin/chalkboard/README.md", + "export/P4_SPD_Presentacion/plugin/chalkboard/plugin (copy).js", + "export/P4_SPD_Presentacion/plugin/chalkboard/img", + "export/P4_SPD_Presentacion/plugin/chalkboard", + "export/P4_SPD_Presentacion/plugin/chart/README.md", + "export/P4_SPD_Presentacion/plugin/chart/plugin.js", + "export/P4_SPD_Presentacion/plugin/chart/chart.min.js", + "export/P4_SPD_Presentacion/plugin/chart", + "export/P4_SPD_Presentacion/plugin/customcontrols/style.css", + "export/P4_SPD_Presentacion/plugin/customcontrols/README.md", + "export/P4_SPD_Presentacion/plugin/menu/CONTRIBUTING.md", + "export/P4_SPD_Presentacion/plugin/menu/README.md", + "conflict-files-obsidian-git.md", + "TERCERO/SS/SS Lab.md", "TERCERO/SS/SS 24-25.md", "TERCERO/ATR1/Teoría_2425.md", - "TERCERO/SS/SS Lab.md", + "Excalidraw/Drawing 2024-10-18 17.50.51.excalidraw.md", + "TERCERO/IA/Teoría_2425.md", "SEGUNDO/ADDA/Teoría_2324.md", "TERCERO/IA/Apuntes Julia.md", "SEGUNDO/IISSI2/Teoría_2324.md", "SEGUNDO/IISSI1/Teoría_2324.md", - "TERCERO/SS/images", - "TERCERO/SPD/images", - "TERCERO/IA/images", - "TERCERO/ATR1/images", "TERCERO/ATR1/Welcome.md", - "SEGUNDO/ADDA/MemoriaPI4_SMT4497.docx", - "SEGUNDO/ADDA/PI4_SMT4497.zip", - "SEGUNDO/ADDA/MemoriaPI5_SMT4497.pdf", "SEGUNDO/ADDA/ADDA 23-24.md", "SEGUNDO/ADDA/MODELOS.md", "SEGUNDO/ADDA/ADDA 15-05.md", "SEGUNDO/ADDA/ADDA 15-03.md", "SEGUNDO/ADDA/ADDA 13-03.md", - "SEGUNDO/AC/Teoría_2324.md", - "TERCERO/IA", - "TERCERO/SS", - "TERCERO/SPD", - "SEGUNDO/MD/Apuntes Sage.md", - "SEGUNDO/RC/Teoría_2324.md", - "SEGUNDO/RC/Untitled.md", - "SEGUNDO/TC/Teoría_2324.md", - "SEGUNDO/SO/Teoría_2324.md", - "SEGUNDO/SO/Untitled.md", - "SEGUNDO/SO/Sin título.md", "SEGUNDO/SO/Sin título.canvas" ] } \ No newline at end of file From e5a78b00e2c8b74a526ea5e02e3416005133636b Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 31 Oct 2024 13:15:22 +0100 Subject: [PATCH 2/2] cambios SS 2024-10-31 13:15:21 --- .obsidian/workspace.json | 14 +++--- TERCERO/SPD/P4_SPD.md | 83 ---------------------------------- TERCERO/SS/SS 24-25.md | 69 ++++++++++++++++++++++++---- conflict-files-obsidian-git.md | 17 ------- 4 files changed, 68 insertions(+), 115 deletions(-) delete mode 100644 TERCERO/SPD/P4_SPD.md delete mode 100644 conflict-files-obsidian-git.md diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index b7ea70d..ce65e6b 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -4,21 +4,21 @@ "type": "split", "children": [ { - "id": "90d0925ab4ee2d0c", + "id": "1b63d80607fcf1ef", "type": "tabs", "children": [ { - "id": "3b843e69b2a87354", + "id": "ab1a9c31dcf2580f", "type": "leaf", "state": { "type": "markdown", "state": { - "file": "conflict-files-obsidian-git.md", + "file": "TERCERO/SS/SS 24-25.md", "mode": "source", "source": false }, "icon": "lucide-file", - "title": "conflict-files-obsidian-git" + "title": "SS 24-25" } } ] @@ -175,17 +175,17 @@ "obsidian-advanced-slides:Show Slide Preview": false } }, - "active": "3b843e69b2a87354", + "active": "ab1a9c31dcf2580f", "lastOpenFiles": [ + "TERCERO/SPD/Teoría_2425.md", + "TERCERO/SPD/P4_SPD.md", "conflict-files-obsidian-git.md", "TERCERO/SS/images/Pasted image 20241024113018.png", "TERCERO/SS/images/Pasted image 20241024090239.png", - "TERCERO/SPD/Teoría_2425.md", "TERCERO/SPD/Guión Practica 4 SPD.md", "TERCERO/SPD/P4_SPD_Presentacion.md", "TERCERO/SPD/images/Pasted image 20241022144832.png", "TERCERO/SPD/images/Pasted image 20241022150214.png", - "TERCERO/SPD/P4_SPD.md", "TERCERO/SPD/images/Pasted image 20241022144429.png", "TERCERO/SPD/images/Pasted image 20241022134454.png", "TERCERO/SPD/images/Pasted image 20240930084659.png", diff --git a/TERCERO/SPD/P4_SPD.md b/TERCERO/SPD/P4_SPD.md deleted file mode 100644 index 7032c64..0000000 --- a/TERCERO/SPD/P4_SPD.md +++ /dev/null @@ -1,83 +0,0 @@ -# ASM / C -### a) ¿Qué hace el código? -Recorre el array `arrayx` (empezando por la posición 1) de tamaño `N_ITER` almacenando en la posición `i - 1` la suma del elemento `i` más el `i + 1` entre la constante `f11`. -### b) ¿Cómo se puede escribir en alto nivel? -```C -#define N_ITER 25 - -float arrayx[N_ITER]; -const float f11 = 21.0; - -for(int i = 1; i < N_ITER; i++) -{ - arrayx[i - 1] = ( arrayx[i] + arrayx[i + 1] ) / f11; -} -``` -### c) ¿Son paralelizables directamente? -Sí porque no hay dependencias reales. -```C -#define N_ITER 25 - -float arrayx[N_ITER]; -const float f11 = 21.0; - -for(int i = 5; i < N_ITER; i+=5) -{ - arrayx[i - 1] = ( arrayx[i] + arrayx[i + 1] ) / f11; - arrayx[i - 2] = ( arrayx[i + 1] + arrayx[i + 2] ) / f11; - arrayx[i - 3] = ( arrayx[i + 2] + arrayx[i + 3] ) / f11; - arrayx[i - 4] = ( arrayx[i + 3] + arrayx[i + 4] ) / f11; - arrayx[i - 5] = ( arrayx[i + 4] + arrayx[i + 5] ) / f11; -} -``` -### d) Como la BTB predice siempre tomado ¿cuándo acierta? -La BTB acertará en todas las iteraciones del bucle excepto en la última porque predice salto tomado y no debería tomarlo porque el bucle ha acabado. -![[Pasted image 20241022134454.png]] -### e) Si la BTB de un GPP es muy sofisticada ¿acertará en los saltos? -... -# Visual Studio -La función más paralelizable es **`pp4()`** ya que sólo tiene una operación de cada tipo (**`LD, SF, ADDF, SLTI, ADDI`**) y no hay saltos condicionales en el bucle. -```C -double pp4() -{ - int i; - for (i = 0; iMáquina en la que se ejecuta el código real: - -![[Pasted image 20241022144429.png|400]] - -### Comparativa - -| `pp2()` | `nuestro` | -| -------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| double pp2()
{
int i;
for (i = 0; i a[i] = 3.14 / sqrt(b[i]+c[i]);
}
return a[N_ITER - 1];
} | # define N_ITER 25

float arrayx[N_ITER];
const float f11 = 21.0;

for(int i = 1; i < N_ITER; i++)
{
arrayx[i - 1] = ( arrayx[i] + arrayx[i + 1] ) / f11;
} | -| Este código tiene:
- 2x LDF
- 1x STF
- 1x ADDF
- 1x DIVF
- 1x constante | Nuestro código tiene:
- 2x LDF
- 1x STF
- 1x ADDF
- 1x DIVF
- 1x constante | -| | | -### Duración de CPI en los bucles - -| Release | Debug | -| ------------------------------------ | ------------------------------------ | -| ![[Pasted image 20241022144832.png]] | ![[Pasted image 20241022150214.png]] | - -(Todo para config1 y config2) -5. GFLOPS (o MIPS) -6. CPI (pp2 pp4) y Ac -7. Cronograma \ No newline at end of file diff --git a/TERCERO/SS/SS 24-25.md b/TERCERO/SS/SS 24-25.md index cec6699..2c686dc 100644 --- a/TERCERO/SS/SS 24-25.md +++ b/TERCERO/SS/SS 24-25.md @@ -226,21 +226,74 @@ En C/C++ parece fácil: usándolo. La mayoría de SO están escritos en C así q - Funciones terminadas en W (`MessageBoxW`) ### Tratamiento de errores Las funciones devuelven un entero, y si este es negativo es que ha terminado con error. Para más información sobre el error se usa `GetLastError()` y para mensajes al usuario `FormatMessage()`. -# TEMA 5: Control de ejecución: procesos e hilos -En Windows todos los procesos tienen al menos el "main thread". El programa termina cuando termina el hilo principal. Dos modelos básicos: -- **Multihilo:** cada proceso tiene múltiples hilos. Típico de Windows aunque se usa cada vez más en UNIX/Linux. +# TEMA 5: Control de ejecución: procesos e threads +En Windows todos los procesos tienen al menos el "main thread". El programa termina cuando termina el thread principal. Dos modelos básicos: +- **Multithread:** cada proceso tiene múltiples threads. Típico de Windows aunque se usa cada vez más en UNIX/Linux. - **Multiproceso:** múltiples procesos. Típico de UNIX/Linux, aunque también se puede en Windows. En Linux es **muy fácil** usando `fork()`. -## 1. Operaciones básicas con hilos -Organizar la ejecución en varios hilos **¿para qué?** +## 1. Operaciones básicas con threads +Organizar la ejecución en varios threads **¿para qué?** EJEMPLO: Programa de proceso de audio -- **Hilo 1:** lee datos de la entrada de audio, los procesa y envía el resultado a la salida. +- **thread 1:** lee datos de la entrada de audio, los procesa y envía el resultado a la salida. - Periódico - Intensivo en datos - Requiere velocidad de proceso - **WORKER THREADS** -- **Hilo 2:** controla la UI (subir, bajar volumen, play, pause...) Complicado si alguna tarea es bloqueante. +- **thread 2:** controla la UI (subir, bajar volumen, play, pause...) Complicado si alguna tarea es bloqueante. - No periódico - No intensivo - No requiere velocidad de proceso - **USER INTERFACE THREAD** -- \ No newline at end of file +### Crear un thread +En Windows se usa `CreateThread()` que devuelve un `HANDLE`. Los elementos que integran el thread son: +- Función de entrada +- Parámetro(s) +- Pila +- Almacenamiento local al thread +- El HANDLE y el ID +Los threads son **asíncronos**. +#### Ejemplo +```C +int main(int argc, char *argv[]) +{ + setlocale(LC_ALL, "Spanish"); +    + DWORD Ciclo = 1000; // Ciclo entre pitidos (en ms) + DWORD Frecuencia = 500; + DWORD Duracion = 100; + + while (TRUE){ + // bip a frec. y duración que se le pasa + Beep(Frecuencia, Duracion); + Sleep(Ciclo); + } + + printf("\nPulse tecla RETORNO para terminar\n"); + getchar();  // bloqueo + return 0; +} +``` +Para evitar el bloqueo, en C++ existen alternativas (en C **NO**), como `std::thread` o `std::async`. +### Suspender/Reactivar un thread +El thread se puede suspender o reactivar usando respectivamente `SuspendThread` y `ResumeThread`. El thread está suspendido si el contador != 0. +### Terminar un thread +Un thread finaliza cuando termina su función de entrada, cuando se termina a sí mismo con `ExitThread` o cuando lo "terminan" con `TerminateThread`. +## 2. Organización de los datos en un thread +Los hilos comparten variables globales y código. También pueden pasarse punteros (posibilidad de errores). +### Código reentrante +Código que puede ser usado desde más de un hilo. Se puede aplicar a: +- Código completo del hilo +- Algunas funciones +- Bibliotecas +Cada instancia de un thread tiene sus propios recursos, los cuales hay que proteger con mecanismos de control de la concurrencia. +## 3. Creando procesos +`CreateProcess` crea un proceso concurrente. Algunos puntos a destacar en la descripción de `CreateProcess`: +- **`IpApplicationName`**: es opcional. Si es `NULL`, el nombre del programa se incluye en el siguiente parámetro. +- **`IpCommandLine`**: si el path del ejecutable no está, se sigue la secuencia de búsqueda que viene al final de este parámetro. +- **`IpProcessAttributes, IpThreadAttributes, bInheritHandles, IpEnvironment, IpCurrentDirectory`**: no los usaremos, poner a NULL/FALSE. +- **`IpStartupInfo`**: la estructura `STARTUPINFO` no la usaremos pero tiene que estar. +- **`IpProcessInformation`**: rellena la estructura `PROCESS_INFORMATION` con información sobre el proceso y thread creado (handles, process/threads ids). +## 4. Punto de vista de la programación y procesos POSIX +- Aunque el proceso creado se le llama "hijo" **no hay relación lógica** entre ambos, al menos en Windows. En UNIX/Linux/POSIX **sí hay**. +- La creación del proceso es asíncrona, **NO** es una "llamada". +- En la biblioteca de C: `exec` (UNIX) / `_exec` (Win) funcionan distinto en Windows y UNIX/Linux. En Windows se basa en `CreateProcess` y en UNIX/Linux el proceso actual carga un nuevo programa: + - `posix spawn` es lo equivalente a `CreateProcess` que básicamente hace: `fork` + `exec` \ No newline at end of file diff --git a/conflict-files-obsidian-git.md b/conflict-files-obsidian-git.md deleted file mode 100644 index d8bbd4f..0000000 --- a/conflict-files-obsidian-git.md +++ /dev/null @@ -1,17 +0,0 @@ -# Conflicts -Please resolve them and commit them using the commands `Git: Commit all changes` followed by `Git: Push` -(This file will automatically be deleted before commit) -[[#Additional Instructions]] available below file list - -- Not a file: .obsidian/workspace.json - -# Additional Instructions -I strongly recommend to use "Source mode" for viewing the conflicted files. For simple conflicts, in each file listed above replace every occurrence of the following text blocks with the desired text. - -```diff -<<<<<<< HEAD - File changes in local repository -======= - File changes in remote repository ->>>>>>> origin/main -``` \ No newline at end of file