1. Introduction#

1.1. Scientific Computing#

https://en.wikiversity.org/wiki/Scientific_computing https://www.nature.com/articles/d41586-024-00725-1

1.2. High Performance Scientific Computing#

https://en.wikipedia.org/wiki/High-performance_computing?useskin=vector

Image Description
From: "https://www.researchgate.net/publication/336577121_BACKUS_Comprehensive_High-Performance_Research_Software_Engineering_Approach_for_Simulations_in_Supercomputing_Systems/figures?lo=1"
Image Description
From: "https://www.admin-magazine.com/HPC/Articles/Selecting-Compilers-for-a-Supercomputer"
Image Description
From: "https://www.nature.com/articles/s41550-021-01342-y"
Image Description
From: "https://cpufun.substack.com/p/is-fortran-a-dead-language"

1.3. Resources#

  • Online dev env

  • Computer Room

1.5. Videos recorded from classes#

1.6. Shell/bash#

1.7. git#

1.8. C++#

2. Computer Architecture#

See 01-intro.pdf

Check:

  • Branch education, computer hardware: https://www.youtube.com/watch?v=d86ws7mQYIg&t=0s

2.1. Review of C++ Programming#

  • Understand the problem

  • Edit the code

  • Compile

  • Execute and return to the first step

2.1.1. Editing#

Any text editor, but better use an ide like:

2.1.2. Compiling#

Compilation + Linking

g++ filename.cpp

If the compilation is successful, this produces a file called a.out on the current directory. You can execute it as

./a.out

where ./ means “the current directory”. If you want to change the name of the executable, you can compile as

g++ filename.cpp -o executablename.x

Replace executablename.x with the name you want for your executable.

Example program

// Mi primer programa
#include <iostream> 

int main(void) 
{
  std::cout << "Hola Mundo!" << std::endl;
  return 0;
}

Compilation stages:

  • Pre-processing: This does not compile. It just executes the precompiler directives. For instance, it replaces the iostream header and put it into the source code

g++ -E helloworld.cpp
# This instruction counts how many lines my code has now
g++ -E helloworld.cpp | wc -l
  • Compilation : Object code

g++ -c helloworld.cpp
  • Linking and executable: ld, use ldd and nm

g++ helloworld.cpp

2.1.3. Example: Computing the mean of a vector#

#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <numeric>

// function declaration
void fill(std::vector<double> & xdata); // llenar el vector
double average(const std::vector<double> & xdata); // calcular el promedio

int main(int argc, char **argv)
{
  // read command line args
  int N = std::atoi(argv[1]);

  // declare the data struct
  std::vector<double> data;
  data.resize(N);

  // fill the vector
  fill(data);

  // compute the mean
  double result = average(data);

  // print the result
  std::cout.precision(15);
  std::cout.setf(std::ios::scientific);
  std::cout << result << "\n";

  return 0;
}

// function implementation
void fill(std::vector<double> & xdata)
{
  std::iota(xdata.begin(), xdata.end(), 1.0); // 1.0 2.0 3.0
}

double average(const std::vector<double> & xdata)
{
  // forma 1
  return std::accumulate(xdata.begin(), xdata.end(), 0.0)/xdata.size();
  // forma 2
  // double suma = 0.0;
  // for (auto x : xdata) {
  //   suma += x;
  // }
  // return suma/data.size();
}

2.1.4. Loops#

// imprima los numeros del 1 al 10 suando while
#include <iostream> 

int main(void) 
{
  int n;

  n = 1;
  while (n <= 10) {
    std::cout << n << std::endl;
    ++n;  
  } 

  return 0;
}

2.1.5. Condicionales#

// verificar si un numero es par

/* 
   if (condicion) {
   instrucciones
   }
   else {
   instrucciones
   }
 */

#include <iostream> 

int main(void) 
{
  int num;

  // solicitar el numero
  std::cout << "Escriba un numero entero, por favor:" << std::endl;
  // leer el numero
  std::cin >> num;

  // verificar que el numero es par o no
  // imprimir
  // si el numero es par, imprimir "el numero es par"
  // si no, imprimir "el numero es impar"
  if (num%2 == 0) {
    std::cout << "El numero es par" << std::endl;
  } 
  if (num%2 != 0) {
    std::cout << "El numero es impar" << std::endl;
  } 

  //else {
  //cout << "El numero es impar" << endl;
  //}

  return 0;
}