Superscalar — The Easy Way!

I really enjoy taking courses with useful, practical content. It doesn’t happen all the time, but I’ve had a good run of luck recently. Tuesday’s lecture in the ECEC622 Parallel Computer Architecture course I’m taking was about OpenMP — a very easy-to-use, open-source API for C/C++ and Fortran.

OpenMP is what an API should be — both useful and very easy to incorporate into an application, even for programmers encountering it for the first time. Within a few minutes of learning the fundamentals, I was able to write a multithreaded version of the ubiquitous “Hello, World!” program.

Of course, whenever I want to really start to learn a language, architecture, or API, I use it to write a Mandelbrot Set program. Mandelbrot Set calculation lends itself extremely well to parallelization APIs like OpenMP — it’s what programmers refer to as “embarrassingly parallel.”

Here is the Mandelbrot Set calculation code. The OpenMP modifications are shown in blue. Omit them, and the code does exactly the same thing, but without the parallelization.

#include <stdio.h>
#include <omp.h>

//Mandelbrot Set calculation routine, to test
//speedup obtained from using OpenMP

//M. Eric Carr
//mec(eighty-two) .at. drexel (dot...) edu

int main(){
	const double rmin = -2.2;
	const double rmax = 1.4;
	const double imin = -1.8;
	const double imax = 1.8;
	const unsigned long long maxiter = 20000;
	const unsigned long long xres = 2000;
	const unsigned long long yres = 2000;

	double a, b, r, i, h;	//Private variables for threads

	unsigned long long totalcount=0;
	unsigned long long count=0;
	unsigned long long x,y;
	unsigned long long iter;

	double dx, dy;
	dx = (rmax-rmin)/xres;
	dy = (imax-imin)/yres;

	#pragma omp parallel for private(a,b,r,i,h,x,y,iter) reduction(+:count)
	for(y=0;y<yres;y++){
		b = imax-y*dy;
		for(x=0;x<xres;x++){
			r=0;
			i=0;
			a = rmin + x*dx;
			iter=0;
			while(iter<maxiter && r*r+i*i<=4.0){
				h=(r+i)*(r-i)+a;
				i=2*r*i+b;
				r=h;
				iter++;
				}
			if(iter>=maxiter-1){
				count++;}
			} //for x
		} //for y

	#pragma omp barrier

	printf("dx is: %F\n",dx);
	printf("dy is: %F\n",dy);
	printf("Total count is: %lld\n",count);

	dx=count*dx*dy;

	printf("Total area is: %F\n",dx);

	return(0);

	} //main

 

Three extra lines of code, to share the workload among however many CPU cores your system has (eight virtual cores, on a Core i7 CPU). Talk about a good return on your coding time!

Posted in Coding, Digital, Drexel | Leave a comment

Computer Art

Take a rectangular field of arbitrary size (pick something nice like 800×600), fill it with random pixels, then iterate the following code:

* Choose a pixel and one of its neighbors
* Make the neighboring pixel the same color as the first pixel
* Repeat as desired

As an algorithm, it isn’t much to look at — but it produces interesting psychedelic pictures, and it’s fun to watch it in action.

 

Posted in Coding, Digital | Leave a comment

True 8-bit computing!

A while ago, I realized that the DrACo/Z80 was actually quite a bit more complex than it needed to be, to suit the purposes of the EET325 class. Since it is programmed in machine code, the programs written for it tend to be very small, both in terms of code size and memory usage.

Since wire-wrapping all of the connections is by far the most time-consuming part of the build process, this suggested a possible shortcut. Instead of wiring up all sixteen address lines, why not make it a true 8-bit computer — with only eight address lines? Sure, it will only be able to access the first 256 bytes of its memory, but nobody ever uses more than that in the class, anyway. (…and if any students get that ambitious, it can still be upgraded to 16-bit easily enough.)

Here are the updated schematics (including a few bug fixes and annotations). The 74LS245s between the Z80 and the bus have been removed, as well, since even the original 16-bit prototype runs well enough without them.

DrACo/Z80 Control Panel (8-bit version)

DrACo/Z80 Core (8-bit version)

Posted in Digital, DrACo/Z80, Drexel, EET325, Level 4, Projects | Leave a comment

LOLcode

I just came across LOLcode. Best laugh I’ve had in a LONG time. This one’s even funnier than Tenne-C!

Google has even implemented it as a searchable language in Google Code Search. Sweet!

And to think, just today my professor mentioned that we might consider picking up a new language for the parallel-computing project for the class.

Hilarity, as the saying goes, ensues!

Posted in Coding, Humor | Leave a comment