I admit to an almost perverse fondness for command line environments. So I decided to jump onto PowerShell as my default command line environment because its way more cool than the cmd shell and even a nerd with a penchant for undead languages sometimes worries about being cool to some tiny degree. Only know about bash, csh, ksh, or sh? See: http://en.wikipedia.org/wiki/Windows_PowerShell.

One of the things I often do is build very simple little programs to test various features of Windows HPC Server 2008. So when I began using Powershell, I almost immediately ran into a situation where I wanted to do a quick C++ compile from within the PowerShell environment. I have been doing this for a couple of years in cmd shell because Visual Studio provides a shortcut the Tools folder of its start menu item that starts a cmd shell with all the environment variable preset for you.

“Ah ha!”, says I. “I need to do the same thing for PowerShell.” Here are my notes on how I did this and then tested it.

Start with the HPC version of the PowerShell shortcut in the Start menu. You’ll need to install at least the HPC Pack Client Utilities to get this shortcut. See: http://technet.microsoft.com/en-us/library/cc947676.aspx for a quick overview of all the cmdlets you get with this Client Pack.

You’ll also need to install Visual Studio 2008 (or earlier) and the Windows SDK for Server 2008 and HPC Server SDKs to do anything useful.

The Windows SDK for Server 2008 is at:  http://www.microsoft.com/downloads/details.aspx?FamilyID=E6E1C3DF-A74F-4207-8586-711EBE331CDC&displaylang=en.

The HPC SDK is at: http://www.microsoft.com/downloads/details.aspx?familyid=12887DA1-9410-4A59-B903-693116BFD30E&displaylang=en.  

Now, let’s cut to the chase. First get that shortcut.

Start->Microsoft HPC Pack->HPC Powershell and right click and copy it.

Paste it somewhere handy, I put it on my desktop. I also change the ‘Start in:’ field to point to my globally available share rather than my /Users home.

As with all my command shells I turn on Quick Edit and Insert modes in the General tab of properties for this shortcut.

At that location I have a file, pVSvars.ps1, that sets the same environment variables in a Powershell manner as is done for the default Visual Studio command shell.

------------------------------------------------------------------------------

PS C:\Home\fchism> dir pVSvars.ps1

 

 

    Directory: Microsoft.PowerShell.Core\FileSystem::C:\Home\fchism

 

 

Mode                LastWriteTime     Length Name

----                -------------     ------ ----

-a---          3/3/2009   4:14 PM       1686 pVSvars.ps1

 

 

PS C:\Home\fchism> more pVSvars.ps1

 

# Set up Visual Studio Variables for Powershell

 

$env:PATH="C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64;C:\W

indows\Microsoft.NET\Framework64\v3.5;C:\Windows\Microsoft.NET\Framework64\v3.5

\Microsoft .NET Framework 3.5 (Pre-Release Version);C:\Windows\Microsoft.NET\Fr

amework64\v2.0.50727;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\VCPa

ckages;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE;C:\Progra

m Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools;C:\Program Files (x86)\

Microsoft Visual Studio 9.0\Common7\Tools\bin;C:\Program Files\Microsoft SDKs\W

indows\v6.0A\bin\x64;C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\win64\x6

4;C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin;C:\Program Files\Microsoft

SDKs\Windows\v6.0A\Bin\x64;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\wi

n64\x64;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\;$env:PATH"

 

$env:INCLUDE="C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ATLMFC\INCL

UDE;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE;C:\Program Fi

les\Microsoft SDKs\Windows\v6.0A\include;$env:INCLUDE"

 

$env:LIB="C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ATLMFC\LIB\amd6

4;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\LIB\amd64;C:\Program Fi

les\Microsoft SDKs\Windows\v6.0A\lib\x64;$env:LIB"

 

$env:LIBPATH="C:\Windows\Microsoft.NET\Framework64\v3.5;C:\Windows\Microsoft.NE

T\Framework64\v2.0.50727;C:\Windows\Microsoft.NET\Framework64\v3.5;C:\Windows\M

icrosoft.NET\Framework64\v2.0.50727;C:\Program Files (x86)\Microsoft Visual Stu

dio 9.0\VC\ATLMFC\LIB\amd64;C:\Program Files (x86)\Microsoft Visual Studio 9.0\

VC\LIB\amd64;$env:LIBPATH"

 

PS C:\Home\fchism>

 

I have an ‘Unrestricted’ execution policy, so all I have to do at this point is enter .\pVSvars.ps1 at the command prompt. Now I have a Visual Studio Powershell ready to do command line compiling.

As an example, here are the contents of a sample build directory for an MPI hello world build directory.

PS C:\Home\fchism\pSane\MpiHi> dir

 

 

    Directory: Microsoft.PowerShell.Core\FileSystem::C:\Home\fchism\pSane\MpiHi

 

 

Mode                LastWriteTime     Length Name

----                -------------     ------ ----

-a---          2/6/2007  11:13 AM          0 !MPI-HelloWorld

-a---          3/3/2009   4:30 PM        794 Makefile

-a---          5/1/2008   6:10 PM       2632 mpihi.c

-a---          2/6/2007  11:13 AM        428 README

-a---          3/4/2009  10:58 AM       1222 run-mpi.ps1

-a---          3/3/2009   4:20 PM       1006 script-mpihi.cmd

 

--------------------------------------------------------------------------------------

 

Notice that there is both a Makefile and a C source file in this directory. The Makefile is nmake compatible. Here’s the contents of this directory pointing to the Windows HPC Server SDK include and library directories required to build an MPI application for Windows HPC Server 2008. Here are the contents of that Makefile:

PS C:\Home\fchism\pSane\MpiHi> more Makefile

 

# Makefile for Simple MPI Hello World program

#  F. Chism 30August2006

#

# Requires the PATH from starting a Visual Studio cmd shell

# Use nmake not make when building

#

# To build 64-bit version (the default) run from a VS 64-bit cmd shell

#

# namke mpihi.exe

#

# To build a 32-bit version add -DWIN32 to the nmake command and run

#    from a 32-bit cmd shell

#

# namke WIN32=true mpihi.exe

 

CCP_SDK="C:\Program Files\Microsoft HPC Pack 2008 SDK\"

CC=cl

CPPFLAGS=/I "C:\Program Files\Microsoft HPC Pack 2008 SDK\Include"

# Default to 64-bit build

LIBS="C:\Program Files\Microsoft HPC Pack 2008 SDK\Lib\amd64\msmpi.lib"

#!IFDEF WIN32

#LIBS="$(CCP_LIB32)\msmpi.lib"

#!ENDIF

 

 

mpihi.exe: mpihi.c

        $(CC) $(CPPFLAGS)  mpihi.c $(LIBS)

 

clean:

        del mpihi.exe mpihi.obj

 

-------------------------------------------------------------------------------------

 

Now all I have to do is type nmake at the prompt, and voila! A working .exe is created.

 

 

PS C:\Home\fchism\pSane\MpiHi> nmake

 

Microsoft (R) Program Maintenance Utility Version 9.00.21022.08

Copyright (C) Microsoft Corporation.  All rights reserved.

 

        cl /I "C:\Program Files\Microsoft HPC Pack 2008 SDK\Include"  mpihi.c "C

:\Program Files\Microsoft HPC Pack 2008 SDK\Lib\amd64\msmpi.lib"

Microsoft (R) C/C++ Optimizing Compiler Version 15.00.21022.08 for x64

Copyright (C) Microsoft Corporation.  All rights reserved.

 

mpihi.c

Microsoft (R) Incremental Linker Version 9.00.21022.08

Copyright (C) Microsoft Corporation.  All rights reserved.

 

/out:mpihi.exe

mpihi.obj

"C:\Program Files\Microsoft HPC Pack 2008 SDK\Lib\amd64\msmpi.lib"

PS C:\Home\fchism\pSane\MpiHi> dir

 

 

    Directory: Microsoft.PowerShell.Core\FileSystem::C:\Home\fchism\pSane\MpiHi

 

 

Mode                LastWriteTime     Length Name

----                -------------     ------ ----

-a---          2/6/2007  11:13 AM          0 !MPI-HelloWorld

-a---          3/3/2009   4:30 PM        794 Makefile

-a---          3/4/2009  11:36 AM       2638 mpihi.c

-a---          3/4/2009  11:36 AM      53760 mpihi.exe

-a---          3/4/2009  11:36 AM       2806 mpihi.obj

-a---          2/6/2007  11:13 AM        428 README

-a---          3/4/2009  10:58 AM       1222 run-mpi.ps1

-a---          3/3/2009   4:20 PM       1006 script-mpihi.cmd

 

 

PS C:\Home\fchism\pSane\MpiHi> mpiexec -n 8 mpihi.exe

Rank,   2,Headnode

Rank,   6,Headnode

Rank,   7,Headnode

Rank,   1,Headnode

Rank,   5,Headnode

Rank,   4,Headnode

Rank,   3,Headnode

Rank,   0,Headnode

 

Rank 3 to say Hi to rank 4.

Rank 5 to say Hi to rank 6.

Rank 0 to say Hi to rank 1.

Rank 7 to say Hi to rank 0.

Rank 2 to say Hi to rank 3.

Rank 4 to say Hi to rank 5.

Rank 6 to say Hi to rank 7.

Rank 1 to say Hi to rank 2.

 

Rank 5 said 'Hi Powershell Fans' to rank 6.

Rank 1 said 'Hi Powershell Fans' to rank 2.

Rank 7 said 'Hi Powershell Fans' to rank 0.

Rank 0 said 'Hi Powershell Fans' to rank 1.

Rank 3 said 'Hi Powershell Fans' to rank 4.

Rank 4 said 'Hi Powershell Fans' to rank 5.

Rank 6 said 'Hi Powershell Fans' to rank 7.

Rank 2 said 'Hi Powershell Fans' to rank 3.

 

PS C:\Home\fchism\pSane\MpiHi>

 

-------------------------------------------------------------------------------------

I use “Windows PowerShell In Action” as my main study guide for PowerShell. A nice list of books on Powershell can be found at: http://search.barnesandnoble.com/booksearch/results.asp?CAT=1375303 or http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Daps&field-keywords=Powershell or http://www.borders.com/online/store/SearchResults?keyword=powershell&type=0&simple=1 .

Later Dudes and Dudettes,

   Frankie