Matrix multiplication crashes with "iilegal operation" signal (SIGILL)

9 views
Skip to first unread message

Nick

unread,
Oct 23, 2008, 8:46:08 AM10/23/08
to CellDotNet
1. Compile the code

using System;
using System.Threading;
using CellDotNet;

public class MatrixMultThread {

private delegate void multDelegate ( int from, int to, int N, float[]
A,
float[] B, float[] C );

int from;
int to;

int N;

float[] A;
float[] B;
float[] C;

public MatrixMultThread ( int from, int to, int N, float[] A,
float[] B,
float[] C ) {

this.from = from;
this.to = to;
this.N = N;
this.A = A;
this.B = B;
this.C = C;

}

public void run () {

multDelegate fun = mult;

SpeContext.RunProgram ( fun, from, to, N, A, B, C );

}


public static void mult ( int from, int to, int N, float[] A, float[]
B,
float[] C ) {

int i, j, k;
int index;

for ( i = from; i < to; i++ )
for ( j = 0; j < N; j++ ) {
index = i * N + j;
for ( k = 0; k < N; k++ )
C [ index ] = C [ index ] + A [ i * N + k ] * B [ k * N + j ];
}

}

}

public class MatrixMult {

public static void Main ( String[] args ) {

int i, j;

MatrixMultThread mmt;

int N = Convert.ToInt32 ( args [ 0 ] );
int P = Convert.ToInt32 ( args [ 1 ] );

Console.WriteLine ( "N = " + N + " P = " + P );

float[] A = new float [ N * N];
float[] B = new float [ N * N];

float[] C = new float [ N * N ];

Random rand = new Random();

for ( i = 0; i < N; i++ )
for ( j = 0; j < N; j++ ) {
A [ i * N + j ] = (float) rand.NextDouble();
B [ i * N + j ] = (float) rand.NextDouble();
C [ i * N + j ] = 0.0f;
}

Thread[] threads = new Thread [ P ];

DateTime dt1 = DateTime.Now;

int q = N / P,
r = N % P;

int from = 0,
to;

for ( i = 0; i < P; i++ ) {

to = from + q + ( i < r ? 1 : 0 );

mmt = new MatrixMultThread ( from, to, N, A, B, C );
threads [ i ] = new Thread ( new ThreadStart ( mmt.run ) );
threads [ i ].Start();

from = to;

}

for ( i = 0; i < P; i++ )
threads [ i ].Join();

DateTime dt2 = DateTime.Now;

Console.WriteLine ( " Elapsed time = " + (dt2-dt1).TotalSeconds +
"
secs." );

}

}

2. Run it as
> mono MatrixMultCell.exe 1000 3

3. What is the expected output? What do you see instead?

Tests with 1 and 2 SPUs like

>mono MatrixMultCell.exe 1000 1
>mono MatrixMultCell.exe 1000 2

work fine, but with 3 or more SPUs they give "illegal operation":

Unhandled Exception: System.ExecutionEngineException: SIGILL
at <0x00000> <unknown method>
at (wrapper managed-to-native) UnsafeNativeMethods:spe_context_run
(intptr,uint&,uint,intptr,intptr,CellDotNet.SpeContext/SpeStopInfo&)
at CellDotNet.SpeContext.Run (CellDotNet.Spe.DataObject
ppeCallDataArea, CellDotNet.Spe.Marshaler marshaler) [0x00000]
at CellDotNet.SpeContext.RunProgram (CellDotNet.CompileContext cc,
System.Object[] arguments) [0x00000]
at CellDotNet.SpeContext.RunProgram (System.Delegate delegateToRun,
System.Object[] arguments) [0x00000]
at MatrixMultThread.run () [0x00000]
Reply all
Reply to author
Forward
0 new messages