threads

Course: CS 380, Fall 2007
School: University College of...
Rating:
 
 
 
 
 

Word Count: 4834

Document Preview

Shared Programming Address Space Platforms Adapted from Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar ``Introduction to Parallel Computing'', Addison Wesley, 2003. Overview Thread Basics The POSIX Thread API Synchronization Primitives in Pthreads Controlling Thread and Synchronization Attributes Composite Synchronization Constructs OpenMP: a Standard for Directive Based Parallel Programming...

Register Now

Unformatted Document Excerpt

Coursehero >> Puerto Rico >> University College of the Caribbean >> CS 380

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
Shared Programming Address Space Platforms Adapted from Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar ``Introduction to Parallel Computing'', Addison Wesley, 2003. Overview Thread Basics The POSIX Thread API Synchronization Primitives in Pthreads Controlling Thread and Synchronization Attributes Composite Synchronization Constructs OpenMP: a Standard for Directive Based Parallel Programming Process vs Threads Thread Basics Each thread has its own stack, SP, PC, registers, etc. Threads share global variables and heap. Caveat: writing programs in which shared space is treated as a flat address space may give poor performance Locality is just as important in shared-memory machines as it is in distributed-memory machines Thread Basics The logical machine model of a threadbased programming paradigm. The POSIX Thread API Commonly referred to as Pthreads, POSIX has emerged as the standard threads API, supported by most vendors. The concepts discussed here are largely independent of the API and can be used for programming with other thread APIs (NT threads, Solaris threads, Java threads, etc.) as well. Thread Basics: Creation and Termination Creating Pthreads: #include <pthread.h> int pthread_create ( pthread_t *thread_handle, const pthread_attr_t *attribute, void * (*thread_function)(void *), void *arg); Thread is created and it starts to execute thread_function with parameter arg Terminating threads Thread terminated when: o it returns from its starting routine, or o it makes a call to pthread_exit() Main thread exits with pthread_exit(): other threads will continue to execute Otherwise: othereads automatically terminated Cleanup: pthread_exit() routine does not close files any files opened inside the thread will remain open after the thread is terminated. #include <pthread.h> #include <stdio.h> #include <stdlib.h> #define NUM_THREADS 5 void *PrintHello(void *threadid) { printf("\n%d: Hello World!\n", threadid); pthread_exit(NULL); } int main(int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc, t; for(t=0;t<NUM_THREADS;t++){ printf("Creating thread %d\n", t); rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t); if (rc){ printf("ERROR; return code from pthread_create() is %d\n", rc); exit(-1); } } pthread_exit(NULL); } Output Creating thread 0 Creating thread 1 0: Hello World! 1: Hello World! Creating thread 2 Creating thread 3 2: Hello World! 3: Hello World! Creating thread 4 4: Hello World! Synchronizing threads "Joining" is one way to synchronize threads (not used very often) pthread_join (threadid,status) The pthread_join() function blocks the calling thread until the specified thread terminates. The programmer can obtain the target thread's termination return status if it was specified in the target thread's call to pthread_exit(). Threads: Example 2 1.0 1.0 Area of circle = pi*0.25 Area of square = 1 So if we shoot randomly into square, probability of hitting circle is pi*0.25 Estimating value of pi: generate a large number of random values inside the unit square see what fraction of them fall inside circle and multiply by 4 Simple example of Monte Carlo method: estimate some value by repeated sampling of some space Monte Carlo method can be easily parallelized provided each parallel thread generates independent random numbers Threads: Example2 #include <pthread.h> #include <stdlib.h> #define MAX_THREADS 512 void *compute_pi (void *); .... main() { ... pthread_t p_threads[MAX_THREADS]; pthread_attr_t attr; pthread_attr_init (&attr); for (i=0; i< num_threads; i++) { hits[i] = i; pthread_create(&p_threads[i], &attr, compute_pi, (void *) &hits[i]); } for (i=0; i< num_threads; i++) { pthread_join(p_threads[i], NULL); total_hits += hits[i]; } ... } Threads: Example2 (contd.) void *compute_pi (void *s) { int seed, i, *hit_pointer; double rand_no_x, rand_no_y; int local_hits; hit_pointer = (int *) s; seed = *hit_pointer; local_hits = 0; for (i = 0; i < sample_points_per_thread; i++) { rand_no_x =(double)(rand_r(&seed))/(double)((2<<14)-1); rand_no_y =(double)(rand_r(&seed))/(double)((2<<14)-1); if (((rand_no_x - 0.5) * (rand_no_x - 0.5) + (rand_no_y - 0.5) * (rand_no_y - 0.5)) < 0.25) local_hits ++; seed *= i; } *hit_pointer = local_hits; pthread_exit(0); } Synchronizing threads Style of computing shown in Example 2 is sometimes called fork-join parallelism fork join This style of parallel execution in which threads only synchronize at the end is quite rare Usually, threads need to synchronize during their execution Need for synchronization Two common scenarios: Mutual exclusion Shared resource such as variable or device Only one thread at a time can access resource Critical section: portion of code that should be executed by only thread at a time Producer-consumer One thread (producer) generates a sequence of values Another thread (consumer) reads these values Values are communicated by writing them into a shared buffer Producer must block if buffer is full Consumer must block if buffer is empty Need for Mutual Exclusion When multiple threads attempt to manipulate the same data item, the results can often be chaotic if proper care is not taken to synchronize them. Consider: Assume that there are two threads, the initial value of best_cost is 100, and the values of my_cost are 50 and 75 at threads t1 and t2. Depending on the schedule of the threads, the value of best_cost could be 50 or 75! Thread 1 reads best_cost (100) Thread 2 reads best_cost (100) Thread 1 writes best_cost (50) Thread 2 writes best_cost (75) /* each thread tries to update variable best_cost as follows */ if (my_cost < best_cost) best_cost = my_cost; The value 75 does not seem right because it would not arise in a sequential execution of the same algorithm General problem The code in the previous example is called a critical section Several threads may try to execute code in critical section but only one should succeed at a time Problem arises very often when writing threaded code Thread A want to read and write one or more variables in critical section While it is doing that, other threads should be excluded from accessing those variables Solution: lock Threads compete for acquiring lock Pthreads implementation guarantees that only one thread will succeed in acquiring lock Successful thread enters critical section, performs its activity When critical section is done, lock is released Discussion Lock is implemented by variable with two states: available/not_available When thread tries to acquire a lock and state of lock is available, its state is changed to not_available, and thread is informed that it can proceed Pthreads implementation ensures that this is done atomically: cannot interrupt the processor or contextswitch during the lock acquire Detail: locks also have queues that hold ids of threads waiting to acquire lock When one thread releases a lock, next thread in queue is informed it has acquired lock, and it can proceed This is more efficient than alternatives like busy-waiting in which a thread repeatedly tries to acquire a lock This is also a way to ensure some notion of fairness any thread that wants to acquire a lock can succeed ultimately even if other threads want to acquire the lock an unbounded number of times Mutex in Pthreads The Pthreads API provides the following functions for handling mutex-locks: Lock creation int pthread_mutex_init ( pthread_mutex_t *mutex_lock, const pthread_mutexattr_t *lock_attr); Acquiring lock int pthread_mutex_lock ( pthread_mutex_t *mutex_lock); Releasing lock int pthread_mutex_unlock ( pthread_mutex_t *mutex_lock); Correct Mutual Exclusion We can now write our previously incorrect critical section as: pthread_mutex_t minimum_value_lock; ... main() { .... pthread_mutex_init(&minimum_value_lock, NULL); .... } void *find_min(void *list_ptr) { .... pthread_mutex_lock(&minimum_value_lock); if (my_min < minimum_value) critical section minimum_value = my_min; /* and unlock the mutex */ pthread_mutex_unlock(&minimum_value_lock); } Critical sections For performance, it is important to keep critical sections as small as possible While one thread is within critical section, all others threads that want to enter the critical section are blocked It is up to the programmer to ensure that locks are used correctly to protect variables in critical sections Thread A lock(l) x:= ..x.. unlock(l) Thread B Thread C lock(l) x:= ..x.. x: = x unlock(l) This program may fail to execute correctly because programmer forgot to use locks in Thread C Producer-Consumer Using Locks Two threads Producer: produces data Consumer: consumes data Shared buffer is used to communicate data from producer to consumer Buffer can contain one data value (in this example) Flag is associated with buffer to indicate buffer has valid data Consumer must not read data from buffer unless there is valid data Producer must not overwrite data in buffer before it is read by consumer Producer-Consumer Using Locks pthread_mutex_t data_queue_lock; int data_available; ... main() { .... data_available = 0; pthread_mutex_init(&data_queue_lock, NULL); .... } void *producer(void *producer_thread_data) { .... while (!done()) { inserted = 0; create_data(&my_data); while (inserted == 0) { pthread_mutex_lock(&data_queue_lock); if (data_available == 0) { insert_into_queue(my_data); data_available = 1; inserted = 1; } pthread_mutex_unlock(&data_queue_lock); } } } Producer-Consumer Using Locks void *consumer(void *consumer_thread_data) { int extracted; struct data my_data; /* local data structure declarations */ while (!done()) { extracted = 0; while (extracted == 0) { pthread_mutex_lock(&data_queue_lock); if (data_available == 1) { extract_from_queue(&my_data); data_available = 0; extracted = 1; } pthread_mutex_unlock(&data_queue_lock); } process_data(my_data); } } Types of Mutexes Pthreads supports three types of mutexes - normal, recursive, and error-check. A normal mutex deadlocks if a thread that already has a lock tries a second lock on it. A recursive mutex allows a single thread to lock a mutex as many times as it wants. It simply increments a count on the number of locks. A lock is relinquished by a thread when the count becomes zero. An error check mutex reports an error when a thread with a lock tries to lock it again (as opposed to deadlocking in the first case, or granting the lock, as in the second case). The type of the mutex can be set in the attributes object before it is passed at time of initialization. Reducing lock overhead It is often possible to reduce the idling overhead associated with locks using an alternate function, pthread_mutex_trylock. int pthread_mutex_trylock ( pthread_mutex_t *mutex_lock); If lock is available, acquire it; otherwise, return a busy error code (EBUSY) Faster than pthread_mutex_lock on typical systems since it does not have to deal with queues associated with locks for multiple threads waiting on the lock. Alleviating Locking Overhead (Example) /* Finding k matches in a list */ void *find_entries(void *start_pointer) { /* This is the thread function */ struct database_record *next_record; int count; current_pointer = start_pointer; do { next_record = find_next_entry(current_pointer); count = output_record(next_record); } while (count < requested_number_of_records); } int output_record(struct database_record *record_ptr) { int count; pthread_mutex_lock(&output_count_lock); output_count ++; count = output_count; pthread_mutex_unlock(&output_count_lock); if (count <= requested_number_of_records) print_record(record_ptr); return (count); } Alleviating Locking Overhead (Example) /* rewritten output_record function */ int output_record(struct database_record *record_ptr) { int count; int lock_status; lock_status=pthread_mutex_trylock(&output_count_lock); if (lock_status == EBUSY) { } else { insert_into_local_list(record_ptr); return(0); count = output_count; output_count += number_on_local_list + 1; pthread_mutex_unlock(&output_count_lock); print_records(record_ptr, local_list, return(count + number_on_local_list + 1); requested_number_of_records - count); } } Condition Variables Condition variables are another construct for more efficient synchronization: permit a thread to be woken up when some predicate on the data is satisifed Example: one thread produces a sequence of data items, and consumer thread must wait till there are more than n items in buffer Busy waiting is inefficient Better to let waiting thread sleep and get notified when predicate is satisifed Solution: condition variables Basic operations using condition variables Thread can wait on condition variable: intuitively, thread blocks until some other thread signals that condition variable Thread can signal condition variable: release one thread waiting on condition variable Condition variables are not boolean variables! Correct operation of condition variables requires an associated mutex as we will see later Condition Variable Constructs Pthreads provides the following functions for condition variables: int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr); int pthread_cond_destroy(pthread_cond_t *cond); int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); int pthread_cond_signal(pthread_cond_t *cond); int pthread_cond_broadcast(pthread_cond_t *cond); Locks associated with condition variables Correct operation with condition variable requires an associated lock Wait and signal must be performed while holding lock Problem: If thread A holds lock, calls wait on a condition variable, and then goes to sleep, how does thread B acquire lock to signal this condition variable? Solution: When thread A calls wait and goes to sleep, pthreads implementation automatically releases associated lock When thread A needs to be woken up in response to signal, pthreads implementation tries to reacquire lock and returns control to application program only after lock has been reacquired Signal and lock reacquire are separate events, so it is good practice to re-check that data predicate after control returns from wait => Use a loop around wait (shown in examples) Producer-Consumer Using Condition Variables pthread_cond_t cond_queue_empty, cond_queue_full; pthread_mutex_t data_queue_cond_lock; int data_available; /* other data structures here */ main() { /* declarations and initializations */ data_available = 0; pthread_init(); pthread_cond_init(&cond_queue_empty, NULL); pthread_cond_init(&cond_queue_full, NULL); pthread_mutex_init(&data_queue_cond_lock, NULL); /* create and join producer and consumer threads */ } Producer-Consumer Using Condition Variables void *producer(void *producer_thread_data) { int inserted; while (!done()) { create_data(); pthread_mutex_lock(&data_queue_cond_lock); while (data_available == 1) pthread_cond_wait(&cond_queue_empty, &data_queue_cond_lock); insert_into_queue(); data_available = 1; pthread_cond_signal(&cond_queue_full); pthread_mutex_unlock(&data_queue_cond_lock); } } Producer-Consumer Using Condition Variables void *consumer(void *consumer_thread_data) { while (!done()) { pthread_mutex_lock(&data_queue_cond_lock); while (data_available == 0) pthread_cond_wait(&cond_queue_full, &data_queue_cond_lock); my_data = extract_from_queue(); data_available = 0; pthread_cond_signal(&cond_queue_empty); pthread_mutex_unlock(&data_queue_cond_lock); process_data(my_data); } } Controlling Thread and Synchronization Attributes The Pthreads API allows a programmer to change the default attributes of entities using attributes objects. An attributes object is a data-structure that describes entity (thread, mutex, condition variable) properties. Once these properties are set, the attributes object can be passed to the method initializing the entity. Enhances modularity, readability, ease and of modification. Attributes Objects for Threads Use pthread_attr_init to create an attributes object. Individual properties associated with the attributes object can be changed using the following functions: pthread_attr_setdetachstate, pthread_attr_setguardsize_np, pthread_attr_setstacksize, pthread_attr_setinheritsched, pthread_attr_setschedpolicy, pthread_attr_setschedparam and Attributes Objects for Mutexes Initialize the attrributes object using function: The function pthread_mutexattr_settype_np can be used for setting the type of mutex specified by the mutex attributes object. pthread_mutexattr_settype_np ( pthread_mutexattr_t *attr, int type); PTHREAD_MUTEX_NORMAL_NP PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_ERRORCHECK_NP pthread_mutexattr_init. Here, type specifies the type of the mutex and can take one of: Composite Synchronization Constructs By design, Pthreads provide support for a basic set of operations. Higher level constructs can be built using basic synchronization constructs. We discuss two such constructs - readwrite locks and barriers. Read-Write Locks In many applications, a data structure is read frequently but written infrequently. For such applications, we should use read-write locks. A read lock is granted when there are other threads that may already have read locks. If there is a write lock on the data (or if there are queued write locks), the thread performs a condition wait. If there are multiple threads requesting a write lock, they must perform a condition wait. With this description, we can design functions for read locks mylib_rwlock_rlock, write locks mylib_rwlock_wlock, and unlocking mylib_rwlock_unlock. Read-Write Locks The lock data type mylib_rwlock_t holds the following: a count of the number of readers, the writer (a 0/1 integer specifying whether a writer is present), a condition variable readers_proceed that is signaled when readers can proceed, a condition variable writer_proceed that is signaled when one of the writers can proceed, a count pending_writers of pending writers, and a mutex read_write_lock associated with the shared data structure Read-Write Locks typedef struct { int readers; int writer; pthread_cond_t readers_proceed; pthread_cond_t writer_proceed; int pending_writers; pthread_mutex_t read_write_lock; } mylib_rwlock_t; void mylib_rwlock_init (mylib_rwlock_t *l) { l -> readers = l -> writer = l -> pending_writers = 0; pthread_mutex_init(&(l -> read_write_lock), NULL); pthread_cond_init(&(l -> readers_proceed), NULL); pthread_cond_init(&(l -> writer_proceed), NULL); } Read-Write Locks void mylib_rwlock_rlock(mylib_rwlock_t *l) { /* if there is a write lock or pending writers, perform condition wait.. else increment count of readers and grant read lock */ pthread_mutex_lock(&(l -> read_write_lock)); while ((l -> pending_writers > 0) || (l -> writer > 0)) pthread_cond_wait(&(l -> readers_proceed), &(l -> read_write_lock)); l -> readers ++; pthread_mutex_unlock(&(l -> read_write_lock)); } Read-Write Locks void mylib_rwlock_wlock(mylib_rwlock_t *l) { /* if there are readers or writers, increment pending writers count and wait. On being woken, decrement pending writers count and increment writer count */ pthread_mutex_lock(&(l -> read_write_lock)); while ((l -> writer > 0) || (l -> readers > 0)) { l -> pending_writers ++; pthread_cond_wait(&(l -> writer_proceed), &(l -> read_write_lock)); } l -> pending_writers --; l -> writer ++; pthread_mutex_unlock(&(l -> read_write_lock)); } Read-Write Locks void mylib_rwlock_unlock(mylib_rwlock_t *l) { /* if there is a write lock then unlock, else if there are read locks, decrement count of read locks. If the count is 0 and there is a pending writer, let it through, else if there are pending readers, let them all go through */ pthread_mutex_lock(&(l -> read_write_lock)); if (l -> writer > 0) l -> writer = 0; else if (l -> readers > 0) l -> readers --; pthread_mutex_unlock(&(l -> read_write_lock)); if ((l -> readers == 0) && (l -> pending_writers > 0)) pthread_cond_signal(&(l -> writer_proceed)); else if (l -> readers > 0) pthread_cond_broadcast(&(l -> readers_proceed)); } Barriers As in MPI, a barrier holds a thread until all threads participating in the barrier have reached it. Barriers can be implemented using a counter, a mutex and a condition variable. A single integer is used to keep track of the number of threads that have reached the barrier. If the count is less than the total number of threads, the threads execute a condition wait. The last thread entering (and setting the count to the number of threads) wakes up all the threads using a condition broadcast. Barriers typedef struct { pthread_mutex_t count_lock; pthread_cond_t ok_to_proceed; int count; } mylib_barrier_t; void mylib_init_barrier(mylib_barrier_t *b) { b -> count = 0; pthread_mutex_init(&(b -> count_lock), NULL); pthread_cond_init(&(b -> ok_to_proceed), NULL); } Barriers void mylib_barrier (mylib_barrier_t *b, int num_threads) { pthread_mutex_lock(&(b -> count_lock)); b -> count ++; if (b -> count == num_threads) { } else b -> count = 0; pthread_cond_broadcast(&(b -> ok_to_proceed)); while (pthread_cond_wait(&(b -> ok_to_proceed), &(b -> count_lock)) != 0); } pthread_mutex_unlock(&(b -> count_lock)); Barriers The barrier described above is called a linear barrier. The trivial lower bound on execution time of this function is therefore O(n) for n threads. This implementation of a barrier can be speeded up using multiple barrier variables organized in a tree. We use n/2 condition variable-mutex pairs for implementing a barrier for n threads. At the lowest level, threads are paired up and each pair of threads shares a single condition variable-mutex pair. Once both threads arrive, one of the two moves on, the other one waits. This process repeats up the tree. This is also called a log barrier and its runtime grows as O(log p). Barrier Execution time of 1000 sequential and logarithmic barriers as a function of number of threads on a 32 processor SGI Origin 2000. Tips for Designing Asynchronous Programs Never rely on scheduling assumptions when exchanging data. Never rely on liveness of data resulting from assumptions on scheduling. Do not rely on scheduling as a means of synchronization. Where possible, define and use group synchronizations and data replication. Types of threads Thread implementations: User-level threads: Implemented by user-level runtime library OS is unaware of threads Portable, thread scheduling can be tuned to application requirements Problem: cannot leverage multiprocessors, entire process blocks when one thread blocks Kernel-level threads: OS is aware of each thread and schedules them Thread operations are performed by OS Can leverage multiprocessors Problem: higher overhead, usually not quite as portable Hybrid-level threads: Solaris OS provides some number of kernel level threads, and each of these can create multiple user-level threads Problem: complexity OpenMP: a Standard for Directive Based Parallel Programming OpenMP is a directive-based API that can be used with FORTRAN, C, and C++ for programming shared address space machines. OpenMP directives provide support for concurrency, synchronization, and data handling while obviating the need for explicitly setting up mutexes, condition variables, data scope, and initialization. OpenMP Programming Model OpenMP directives in C and C++ are based on the #pragma compiler directives. A directive consists of a directive name followed by clauses. OpenMP programs execute serially until they encounter the parallel directive, which creates a group of threads. The main thread that encounters the parallel directive becomes the master of this group of threads and is assigned the thread id 0 within the group. #pragma omp parallel [clause list] /* structured block */ #pragma omp directive [clause list] OpenMP Programming Model The clause list is used to specify conditional parallelization, number of threads, and data handling. Conditional Parallelization: The clause if (scalar expression) determines whether the parallel construct results in creation of threads. Degree of Concurrency: The clause num_threads(integer expression) specifies the number of threads that are created. Data Handling: The clause private (variable list) indicates variables local to each thread. The clause firstprivate (variable list) is similar to the private, except values of variables are initialized to corresponding values before the parallel directive. The clause shared (variable list) indicates that variables are shared across all the threads. OpenMP Programming Model A sample OpenMP program along with its Pthreads translation that might be performed by an OpenMP compiler. OpenMP Programming Model #pragma omp parallel if (is_parallel== 1) num_threads(8) \ private (a) shared (b) firstprivate(c) { /* structured block */ } If the value of the variable is_parallel equals one, eight threads are created. Each of these threads gets private copies of variables a and c, and shares a single value of variable b. The value of each copy of c is initialized to the value of c before the parallel directive. The default state of a variable is specified by the clause default (shared) or default (none). Reduction Clause in OpenMP The reduction clause specifies how multiple local copies of a variable at different threads are c...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

University of Texas - CS - 380
'Transformations and Dependences$&amp;1%'Recall: Polyhedral algebra tools for determining emptiness of convex polyhedra enumerating integers in such a polyhedron. Central ideas: reduction of matrices to echelon form by unimodular column opera
University College of the Caribbean - CS - 380
'Transformations and Dependences$&amp;1%'Recall: Polyhedral algebra tools for determining emptiness of convex polyhedra enumerating integers in such a polyhedron. Central ideas: reduction of matrices to echelon form by unimodular column opera
University of Texas - CS - 380
'Linear Loop Transformations for Locality Enhancement$&amp;1%'Story so far Cache performance can be improved by tiling and permutation Permutation of perfectly nested loop can be modeled as a linear transformation on the iteration space of th
University College of the Caribbean - CS - 380
'Linear Loop Transformations for Locality Enhancement$&amp;1%'Story so far Cache performance can be improved by tiling and permutation Permutation of perfectly nested loop can be modeled as a linear transformation on the iteration space of th
University of Texas - CS - 380
Fractal Symbolic AnalysisKeshav Pingali Cornell UniversityContext: Program Optimization Processor vs. Memory Diskmemory is the bottle-neck small, fast memory units multiple levelsCache Hierarchy Main memory Must pay attention t
University College of the Caribbean - CS - 380
Fractal Symbolic AnalysisKeshav Pingali Cornell UniversityContext: Program Optimization Processor vs. Memory Diskmemory is the bottle-neck small, fast memory units multiple levelsCache Hierarchy Main memory Must pay attention t
University of Texas - CS - 380
Data-parallel Abstractions for Irregular ApplicationsKeshav Pingali University of Texas, AustinMotivation Multicore processors are here but no one knows how to program them A few domains have succeeded in exploiting parallelism Databases: bi
University College of the Caribbean - CS - 380
Data-parallel Abstractions for Irregular ApplicationsKeshav Pingali University of Texas, AustinMotivation Multicore processors are here but no one knows how to program them A few domains have succeeded in exploiting parallelism Databases: bi
University of Texas - CS - 380
Analysis of programs with pointersSimple examplex := 5 ptr := @x *ptr := 9 y := xprogram S1 S2 S3 S4 dependences What are the dependences in this program? Problem: just looking at variable names will not give you the correct information After
University College of the Caribbean - CS - 380
Analysis of programs with pointersSimple examplex := 5 ptr := @x *ptr := 9 y := xprogram S1 S2 S3 S4 dependences What are the dependences in this program? Problem: just looking at variable names will not give you the correct information After
University of Texas - CE - 374
Solutions for Homework 2 McKinney CE374L Chapter 2 Problems (page 83) 1. Prob. 2.2.3. The results of sieving analysis are tabulated below. Using these data, prepare a grain size distribution curve for this sample and assess whether the sample is well
University College of the Caribbean - CE - 374
Solutions for Homework 2 McKinney CE374L Chapter 2 Problems (page 83) 1. Prob. 2.2.3. The results of sieving analysis are tabulated below. Using these data, prepare a grain size distribution curve for this sample and assess whether the sample is well
University College of the Caribbean - CE - 374
1/30/09Unconfined Aquifer Confined AquiferV = Sy A hV = Ss A h11/30/09 +h x h qy = K yy y h qz = K zz z qx = K xx21/30/09 Control volumemass flux inmass flux outqx( qx ) x y zx 2qx +( qx ) x y z =x 2m=
University College of the Caribbean - CE - 374
Solutions for Homework 3 McKinney CE374L Chapter 3 Problems (pages 140-142) 1. Prob. 3.1.1. A confined aquifer with a porosity of 0.15 is 30 m thick. The potentiometric surface elevations at two observation wells 1,000 m apart are 52.35 and 56,90 m.
University of Texas - CE - 374
Saturation Zone Transition ZoneTransmission Zone Wetting ZoneWetting Front z, depthInfiltration rate, fPotential Infiltration Rainfall Actual Infiltrationf (t)TimeF(t) =t 0f ( )df (t) =dF(t) dtGround Surf
University College of the Caribbean - CE - 374
Saturation Zone Transition ZoneTransmission Zone Wetting ZoneWetting Front z, depthInfiltration rate, fPotential Infiltration Rainfall Actual Infiltrationf (t)TimeF(t) =t 0f ( )df (t) =dF(t) dtGround Surf
University of Texas - CE - 374
2/7/0912/7/09 Kxqx h =S t xqx = KKh xxh h =S x txh h h h + Ky + Kz =S x y z y z tGround surface Head in confined aquifer Confining Layer BedrockQxConfined aquiferb Kh1b h(x,y,t)= h(x,y,z,t)dz b01b q x (x,y,t)
University College of the Caribbean - CE - 374
2/7/0912/7/09 Kxqx h =S t xqx = KKh xxh h =S x txh h h h + Ky + Kz =S x y z y z tGround surface Head in confined aquifer Confining Layer BedrockQxConfined aquiferb Kh1b h(x,y,t)= h(x,y,z,t)dz b01b q x (x,y,t)
University of Texas - CE - 374
Q = Aq = (2 rb)Kdh drQ Ground surface Prepumping head Drawdown curve Pumping wellrdh Q = dr 2 Th0Observation wellsConfining Layerbh2r1 h1 r2hwh2 = h1 +Q r ln( 2 ) 2T r1Confined aquiferQBedrockTheim Equation2 Q =
University College of the Caribbean - CE - 374
Q = Aq = (2 rb)Kdh drQ Ground surface Prepumping head Drawdown curve Pumping wellrdh Q = dr 2 Th0Observation wellsConfining Layerbh2r1 h1 r2hwh2 = h1 +Q r ln( 2 ) 2T r1Confined aquiferQBedrockTheim Equation2 Q =
University of Texas - EX - 2004
Addendum to Exercise 3 on downloading data National Elevation Dataset and National Hydrography Dataset from the internet. GIS in Water Resources Fall 2004 Prepared by Venkatesh Merwade, Center for Research in Water Resources University of Texas at Au
University College of the Caribbean - CE - 52005
Addendum to Exercise 3 on downloading data National Elevation Dataset and National Hydrography Dataset from the internet. GIS in Water Resources Fall 2004 Prepared by Venkatesh Merwade, Center for Research in Water Resources University of Texas at Au
University College of the Caribbean - CE - 32005
ncols 5 nrows 4 xllcorner 0 yllcorner 0 cellsize 100 NODATA_value -9999 57 55 47 48 53 67 56 49 53 52 45 42 51 58 40 4148 52 43 40
University of Texas - CE - 311
Solutions for Homework1 McKinney CE311K1. Name the four generations of electronic computers and their respective years of inclusion. 1940 to 1950 1950 to 1964 1964 to 1971 1971 to Present First generation Second generation Third generation Fourth ge
University College of the Caribbean - CE - 311
Solutions for Homework1 McKinney CE311K1. Name the four generations of electronic computers and their respective years of inclusion. 1940 to 1950 1950 to 1964 1964 to 1971 1971 to Present First generation Second generation Third generation Fourth ge
University of Texas - CE - 311
Homework #2 McKinney CE311K Problem 1. Given 3 numbers a, b, and c draw a flowchart illustrating how an algorithm to (1) input the numbers, (2) find the maximum of these three numbers, and (3) output the result would operate.Problem 2. Given one
University College of the Caribbean - CE - 311
Homework #2 McKinney CE311K Problem 1. Given 3 numbers a, b, and c draw a flowchart illustrating how an algorithm to (1) input the numbers, (2) find the maximum of these three numbers, and (3) output the result would operate.Problem 2. Given one
University of Texas - CE - 311
1/15/09 11/15/09 www.tamiya.com 21/15/09 ProgramProgram Call Name( ) End program Sub Name( )Sub procedurestatement(s) End SubThis version does NOT use a sub31/15/09Program calls Sub procedureSub
University College of the Caribbean - CE - 311
1/15/09 11/15/09 www.tamiya.com 21/15/09 ProgramProgram Call Name( ) End program Sub Name( )Sub procedurestatement(s) End SubThis version does NOT use a sub31/15/09Program calls Sub procedureSub
University of Texas - CE - 311
Lab 5 - CE 311 K - McKinneyLab 5 - Selection and Data Types in VBIntroduction The purpose of this assignment is to introduce you to the IfThen statement. After finishing this assignment, you should be able to write a VB program that includes selec
University College of the Caribbean - CE - 311
Lab 5 - CE 311 K - McKinneyLab 5 - Selection and Data Types in VBIntroduction The purpose of this assignment is to introduce you to the IfThen statement. After finishing this assignment, you should be able to write a VB program that includes selec
University of Texas - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinMatricesIntroductionAn important tool
University College of the Caribbean - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinMatricesIntroductionAn important tool
University of Texas - CE - 311
CE311K McKinney Homework 6Functions Problem 1. Given the rational functionf (x) =8x 3x + 5x + 22write a Visual Basic program that computes the values of f(x) when x varies between 5 and 5 with an increment of 0.5. Your program should use a f
University College of the Caribbean - CE - 311
CE311K McKinney Homework 6Functions Problem 1. Given the rational functionf (x) =8x 3x + 5x + 22write a Visual Basic program that computes the values of f(x) when x varies between 5 and 5 with an increment of 0.5. Your program should use a f
University of Texas - CE - 311
Lab 6 - CE 311 K - McKinneyLab 6 - String Variables &amp; Loops in VBAccess Visual Basic 1. Open VB from the start menu, that is:Start\All Programs\Microsoft Visual Basic 2008 Express Edition2. Select FileNew Project to create a new project3. S
University College of the Caribbean - CE - 311
Lab 6 - CE 311 K - McKinneyLab 6 - String Variables &amp; Loops in VBAccess Visual Basic 1. Open VB from the start menu, that is:Start\All Programs\Microsoft Visual Basic 2008 Express Edition2. Select FileNew Project to create a new project3. S
University of Texas - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinLinear EquationsIntroductionIn many e
University College of the Caribbean - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinLinear EquationsIntroductionIn many e
University of Texas - CE - 311
Lab 7 - CE 311 K - McKinneyLab 7 - ArraysIntroduction During the design of reservoirs it is often necessary to know the amount of water that can be taken from a river at a site of interest. The &quot;firm yield&quot; of a site on a river is the largest amou
University College of the Caribbean - CE - 311
Lab 7 - CE 311 K - McKinneyLab 7 - ArraysIntroduction During the design of reservoirs it is often necessary to know the amount of water that can be taken from a river at a site of interest. The &quot;firm yield&quot; of a site on a river is the largest amou
University of Texas - CE - 311
92 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 19
University College of the Caribbean - CE - 311
92 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 19
University of Texas - CE - 311
Lab 8 - CE 311 K - McKinneyLab 8 - FunctionsIntroduction Visual Basic programs are comprised of one or more modules or procedures. In VB, these procedures are either &quot;sub-procedures&quot; or &quot;functions&quot;. Each procedure is a self-contained block of code
University College of the Caribbean - CE - 311
Lab 8 - CE 311 K - McKinneyLab 8 - FunctionsIntroduction Visual Basic programs are comprised of one or more modules or procedures. In VB, these procedures are either &quot;sub-procedures&quot; or &quot;functions&quot;. Each procedure is a self-contained block of code
University of Texas - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinErrors and Stopping CriteriaNumerical
University College of the Caribbean - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinErrors and Stopping CriteriaNumerical
University of Texas - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinNonlinear EquationsIntroductionIn thi
University College of the Caribbean - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinNonlinear EquationsIntroductionIn thi
University of Texas - CE - 311
Lab 9 - CE 311 K - McKinneyLab 9 - Bisection MethodIntroduction In this lab, we will explore a method that we have considered in class for solving nonlinear equations, the bisection method. Given a nonlinear function f(x), we seek a value of x for
University College of the Caribbean - CE - 311
Lab 9 - CE 311 K - McKinneyLab 9 - Bisection MethodIntroduction In this lab, we will explore a method that we have considered in class for solving nonlinear equations, the bisection method. Given a nonlinear function f(x), we seek a value of x for
University of Texas - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinRegressionIntroductionConsider the na
University College of the Caribbean - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinRegressionIntroductionConsider the na
University of Texas - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinNumerical IntegrationIntroduction Trap
University College of the Caribbean - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinNumerical IntegrationIntroduction Trap
University of Texas - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinNumerical DifferentiationIntroduction
University College of the Caribbean - CE - 311
Numerical Methods for Civil EngineersLecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at AustinNumerical DifferentiationIntroduction
University of Texas - CS - 354
Department of Computer SciencesGraphics Fall 2003 (Lecture 2)Pixels Pixel: Intensity or color sample. Raster Image: Rectangular grid of pixels. Rasterization: Conversion of a primitives geometric representation into A set of pixels. An int
University College of the Caribbean - CS - 354
Department of Computer SciencesGraphics Fall 2003 (Lecture 2)Pixels Pixel: Intensity or color sample. Raster Image: Rectangular grid of pixels. Rasterization: Conversion of a primitives geometric representation into A set of pixels. An int
University of Texas - CS - 354
Department of Computer SciencesGraphics Fall 2003 (Lecture 3)Basic User Interface ConceptsA short outline of input devices and the implementation of a graphical user interface is given: Physical input devices used in graphics Virtual dev
University College of the Caribbean - CS - 354
Department of Computer SciencesGraphics Fall 2003 (Lecture 3)Basic User Interface ConceptsA short outline of input devices and the implementation of a graphical user interface is given: Physical input devices used in graphics Virtual dev