Newer
Older
C# is available on the cluster.
```console
$ ml av mono
-------------------- /apps/modules/lang ---------------
Mono/5.0.0.100
```
!!! note
Use the command `ml av mono` to get up-to-date versions of the modules.
Activate C# by loading the Mono module:
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
```console
$ ml Mono
```
## Examples
### Hello World
Copy this code to new file hello.cs:
```csc
using System;
class HelloWorld {
static void Main() {
Console.WriteLine("Hello world!!!");
}
}
```
Compile the program and make *Windows executable*.
```console
$ mcs -out:hello.exe hello.cs
```
Now run the program:
```console
$ mono hello.exe
Hello world!!!
```
### Interactive Console
Type:
```console
$ csharp
Mono C# Shell, type "help;" for help
Enter statements below.
csharp>
```
Now you are in interactive mode. You can try following example.
```csc
csharp> using System;
csharp> int a = 5;
csharp> double b = 1.5;
csharp> Console.WriteLine("{0}*{1} is equal to {2}", a,b,a*b);
5*1.5 is equal to 7.5
csharp> a == b
false
```
Show all files modified in last 5 days:
```csc
csharp> using System.IO;
csharp> from f in Directory.GetFiles ("mydirectory")
> let fi = new FileInfo (f)
> where fi.LastWriteTime > DateTime.Now-TimeSpan.FromDays(5) select f;
{ "mydirectory/mynewfile.cs", "mydirectory/script.sh" }
```
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
## MPI.NET
MPI is available for mono.
```csc
using System;
using MPI;
class MPIHello
{
static void Main(string[] args)
{
using (new MPI.Environment(ref args))
{
Console.WriteLine("Greetings from node {0} of {1} running on {2}",
Communicator.world.Rank, Communicator.world.Size,
MPI.Environment.ProcessorName);
}
}
}
```
Compile and run the program on Anselm:
```console
$ qsub -I -A DD-13-5 -q qexp -l select=2:ncpus=16,walltime=00:30:00
$ ml mpi.net
$ mcs -out:csc.exe -reference:/apps/tools/mpi.net/1.0.0-mono-3.12.1/lib/MPI.dll csc.cs
$ mpirun -n 4 mono csc.exe
Greetings from node 2 of 4 running on cn204
Greetings from node 0 of 4 running on cn204
Greetings from node 3 of 4 running on cn199
Greetings from node 1 of 4 running on cn199
```
For more informations look at [Mono documentation page](http://www.mono-project.com/docs/).