Prep for Parallella's 64 Cores: Installing Go on Mac OS X
22 Jun 2013The idea of owning a 64-core parallel system for two hundred dollars (yes, $200.00) is exciting. Parallella is working to make that happen, perhaps as early as August 2013. To prepare for that day, I’ve decided to introduce myself to the Go language.
What is Go?
The Go language is designed for parallel systems. Why does Go exist? One developer sums it up this way:
Go was created at Google, by Google, for Google-size problems.
~Dave Astels
Google writes software that runs on thousands of machines in parallel. As the number of concurrent operations increases, new challenges are encountered. Google addressed those challenges by creating Go.
Why Does a Rubyist Learn Go?
The team at WisdomGroup writes web and mobile apps, mainly in Ruby. So why am I learning Go?
Because the best developers are polyglot. When we learn a new language, we cause ourselves to see old problems in new ways and we strengthen our ability to solve new problems. It’s like cross-training for athletes. In the end, we become better developers.
How to Install Go on Mac OS X
- Download the binary of Go that matches your system but don't install it yet. You will need to complete the rest of these steps before installation. For my 2010 i5-based 15-inch MacBook Pro, I chose
go1.1.1.darwin-amd64.pkg
. I was concerned about the reference toamd64
in the name. But the description includesMac OS X (x86 64-bit)
, and the binary worked for me. - If you are upgrading from a previous version of Go, you will need to remove the old Go directory. You can do this while the new binary is downloading in the background:
$ rm -rf /usr/local/go
- Define the
GOROOT
andGOPATH
environmental variables. My system uses~/.bash_profile
to define environmental variables, so I added the following lines to the end of that file:
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=~/Code/gocode
- Note: I'm using the default
GOROOT
variable, but yourGOPATH
may differ from mine. I store all of my source code in a subdirectory of home:~/Code
. My complete Go directory structure is given below. By looking at my structure, you can adjust these steps to fit your system. - Tell your terminal session to recognize the new environmental variables. You can either restart terminal, or if your environmental variables are in
~/.bash_profile
like mine, you can do the following:
$ source ~/.bash_profile
- Run the package installation program,
go1.1.1.darwin-amd64.pkg
, that was downloaded in Step 1.
Now, let’s Go for a test drive.
Creating a Go Workspace
Before you can run a Go program on your system, you have to create a Go workspace. A workspace is a directory structure that contains source code and binaries that a Go program needs in order to compile and execute.
We can examine the Go Workspace on my system with the Unix tree
command:
~/Code/gocode$ tree
.
└── src
└── github.com
└── rayhightower
└── hello
└── hello.go
4 directories, 1 file
~/Code/gocode$
Here’s a brief description of the directories:
- Code = root directory for all source code on my system. Yours may differ.
- gocode = where I store all of the Go code on my system. I’m following the structure recommended by the Go documentation. I may alter this as I learn more about the language.
- src = source code
- github.com = directory named after the place where I store repos
- rayhightower = my GitHub profile name
- hello = directory named for our first Go application
- hello.go = the Go source file for our
Hello World
program
All structure below the gocode
directory is mandated by Go.
Writing ‘Hello World!’ in Go
Google’s official installation instructions include a simple ‘Hello World’ program for testing the installation. A slightly modified version appears below:
package main
import "fmt"
func main() {
fmt.Printf("\n** Hey Parallella enthusiasts: Learn Go! **\n")
}
Compiling and Running
We drop the code into a file called hello.go
in the hello
directory. To compile the program:
~/Code/gocode/src/github.com/rayhightower/hello$ go install
~/Code/gocode/src/github.com/rayhightower/hello$
If the Go compiler responds with a blank prompt (like above) then the program compiled successfully and a bin
directory has been created inside the Go workspace. Run the tree
command from the gocode
directory to see how the structure has changed:
~/Code/gocode$ tree
.
├── bin
│ └── hello
└── src
└── github.com
└── rayhightower
└── hello
└── hello.go
5 directories, 2 files
~/Code/gocode$
The newly created bin/
directory contains our hello
executable. And now, let’s cut the suspense and run the program. To do so, change into the bin/
directory and type ./hello
.
~/Code/gocode/src/github.com/rayhightower/hello$ cd ~/Code/gocode/bin
~/Code/gocode/bin$ ./hello
** Hey Parallella enthusiasts: Learn Go! **
~/Code/gocode/bin$
Success!
It’s Not Official, But It Makes Sense
As of this writing, Parallella does not officially support the Go language. So why go through all of this trouble? Because…
- A 64-core Parallella is just too cool to pass up. And it’s open source.
- Go is designed for parallel systems. And it’s open source.
- Open source devs are working on a Go compiler for Parallella right now. If you’re reading this, and you’re one of the devs, thank you!
The Go-Parallella match makes sense. It’s always good to skate where the puck is going.
Next Steps
Now it’s time to explore the Go language. The real adventure begins when the 64-core Parallella arrives. Looking forward to it!
Acknowledgements
I was inspired to explore Go by Blake Smith’s presentation at 8th Light. Justin Love introduced me to Parallella last month at ChicagoRuby.