PP Test 1
communicators
-a collection of processes that can send messages to each other -MPI_Init defines one of these that consists of all the processes created when the program is starts -MPI_COMM_WORLD is pedefined and its purpose is to include all processes
concurrent computing
-a program is one in which multiple task can be in progress at any instant -2+ tasks can start, run , conclude in overlapping time periods
parallel computing
-a program is one in which multiple task cooperate closely to solve a problem -tasks literally run at the same time like on a multicore -execution occurs at same instant with goal of speeding up computations -usually runs simultaneously on cores that are physically close to each other and either share same memory or are connected to a very high speed network
distributed computing
-a program may need to cooperate with other programs to solve a problem -loosley coupled -tasks may be executed by multiple computers that are separated by large distances and the tasks themselves are executed by programs that were created independently
register register int speed;
-a storage class that defines LOCAL VARIABLES to be stored in ___(same name)___ instead of RAM. so not main memory -the variable is subject to size limitations dictated by the ___(same name)___ size -smaller storage but faster speed because it is accessible right away since it is closer to the CPU - doesn't have a memory location give a declaration example of this for variable speed
pointer int num = 23; int *intptr; intptr = # intptr; //prints actual address *intptr; //prints 23 *intptr = 20; //puts 20 in num
-a variable that holds the address of a memory location accessible by using the address operator & - use * (the indirection operator) to indicate this type of variable -can initialize to null -making it a constant will keep the same address but the value of the address's variable can change give an example of assignment of this variable
structure struct Student{ int student ID; short year; double gpa; };
-data type that allows multiple variables to be grouped together - the different fields in this are all public by default -can pass just members or entire structure through functions, function must define a local structure variable tho for internal use. so save space and time use a const reference parameter void showData(const Student &s) -can also do an array of structs give an example of the declaration format, which is only a template to create the box and holds no info, doesn't create variables, and hasn't allocated memory yet
distributed memory systems
-each core has its own private memory -the cores communicate explicitly by doing something like sending messages across a network -MPI (message passing interface), which can use on a regular computer
threads
-lightweight processes because the time and resources and memory requires are smaller than process -each are related
static static int count = 5;
-storage class that automatically initializes to zero upon memory allocation -lasts as long as the program runs -it will remember the last value it was given
shared memory systems
-the cores can share access to the computer's memory -in principle each core can (R,W) any location in memory -can coordinate the cores by having them examine and update shared-memory location
array #define ISIZE 5; int tests [ISIZE];
-variable that can store multiple values of the same type -values are stored in consecutive memory locations for faster access -allocated memory -declaration using [] operator -each element has a subscript used to access it -subscripts start at 0 -to access each element use a for loop -can be initialized during program execution with assignment statements or can be initialized at the definition with an initialization list -must use a loop to copy element by element, can't use an assignment statement -can't compare with a single expression, must use a while loop with boolean variable -have to use a loop to do anything with all the elements as a whole give an example of declaring int variable ISIZE and using it to be the size declaration in creating an int array called test
MPI (message passing interface)
-work in shared memory and distributed memory -need to add mpi.h header file -identifiers defined by MPI start with "MPI_" -in main must start with: MPI_Init(NULL, NULL); //(argument count, pointer to arguments) -in main must end with: MPI_Finalize(); then mains return 0;
divide and conquer do more per unit of time valid solutions faster than regular sequential approach study BIG and complex problems
advantages of parallel
void func(void){ stuff to do return; } after main
give an example of a function definition where is it
for(i = 0; i < 5; i++){ printf("%d\n", tests[i]);
give an example of accessing elements of tests and printing them with a for loop
#include <stdio.h> main(){ int i; // declare variable i printf("Enter a number of type 'int': "); scanf("%d", &i); // type specifier, variable name printf("Value entered: %d\n", i);}
give an example of how to use scanf asking the user to enter a number of type int
printf("The number is %d.\n", number);
give an example of printf function that says "The number is ___." and prints the number variable
bool areEqual = true; int index = 0; while (areEqual && index < ISIZE){ if(tests[index] != tests2[index] areEqual = false; index++;}
give an example of seeing if array tests and tests2 are equal
int tests[5] = {1,2,3,4,5}; // also int tests[] = {1,2,3,4,5}; tests[0] = 4; tests[i]; // int variable tests[i+j]; // int expression
give an example of: create an int array tests of 5 elements and fill with numbers 1-5 putting value 4 in element 0 of tests using an int variable to access an element of tests using int expression to access an element of tests
func(); in main
give example of function call where is it
void func(void); below include headers and above/outside main
give example of function declaration where is it
do { statements; } while(xxx);
give structure of a do loop
while(xxx){ statements; }
give structure of a while loop
mod 10%3 1
holds the value of the remainder of a number divided by another what would the notation look like for remainder of 10/3 what is the answer
nested for loop
how do you traverse a 2D array
1 byte
how much storage size is char, unsigned char, and signed char
8 byte 15 decimal places (double- precision floating point value)
how much storage size is double what is double's precision
4 byte 6 decimal places (single precision floating point value)
how much storage size is float what is float's precision
2 or 4 bytes
how much storage size is int and unsigned int
4 bytes
how much storage size is long and unsigned long
10 byte 19 decimal places
how much storage size is long double what is long double's precision
2 bytes
how much storage size is short and unsigned short
#define PI 3.1416 note: no "=" and no ";" and no data type (float, int, etc) can also use const float PI = 3.1416;
how would you define the constant pi
add the header file #include <myconst.h>
if you have you constants in a separate file (i.e. file name: myconst.h) and you want to include it in your main file what do you do
Student s1; s1.studentID = 1249; s1.year = 12; s1.gpa = 3.89; also Student s1 = {1249, 12, 3.89};
initialize the student structure for someone with an id 1249, year 12, and gpa 3.89
void showScores(int []); // function prototype showScores(tests); // function call void showScores(int tests[]){ // function header/definition }
show in all three function parts how to pass an entire array tests
parallelizing the trapezoidal rule
trapezoid area = .5h(base1 + base2) h = (b-a)/n = width of each trapezoid area of ONE trapezoid = (h/2)[f(xi) + f(xi+1)] sum of trapezoid areas = h[f(x0)/2 + f(x1) + f(x2) + .. + f(xn-1) + f(xn)/2] -basically evenly distribute the area under the curve into equal trapezoids that will be worked on separately by processes and summed together at the very end by one process. -each process uses the same formula just with different information from different parts of the area under the curve. each process is working independently of each other without communicating. -there is a margin of error we have to account for that the trapezoids don't cover since we're trying to find area under a curve. to lower the error split the area up into more trapezoids
local variable
variable created inside a function -not automatically initialized to 0 -it lasts as long as the function is executed and once the fuction concludes then the variable is gone
global variable
variable created outside main function -auto intitialized -lasts as long as the program runs
declaration, definition, call
what 3 things does each function need
#include <mpi.h>
what do we need in our code in order to use mpi routines, definitions, etc
if/else statements if (){ } else if(){ } else{ }
what is branching
executes depending on which case requirement it fulfills, and if no case is applied you use a default switch(x){ case CONSTANT1: // if x == CONSTANT1, statement 1 executes statement1; break; case CONSTANT2: // if x == CONSTANT2, statement 2 executes statement2; break; default: // if x matches no case default_statement: break; }
what is switch
tests[i]++; adds 1 to tests[i] tests[i++]; increments i so that you access a diff element of tests
what is the difference between tests[i]++; and tests[i++];
y = ++x first increase current content of x by 1 then assign content to y y = x++ first assign content of x to y then increase x's content by 1
what is the difference between y = ++x and y = x++
to capture a single numerical character from the keyboard (user) ch = getch();
what is the getch() function what would calling it look like
!
what is the notation for negation (not)
!=
what is the notation for not equal to
capture a number from the keyboard (user) scanf("%TypeSpecifier", &VariableName);
what is the scanf() function
low balancing
when the work load is evenly distributed between the processes