Silverfrost Forums

Welcome to our forums

CallbackOnCollectedDelegate err when calling fortran by .net

24 Sep 2009 8:34 #5026

In my managed main-program (.net c#) i fill up a matrix and vector and call a frotran routine:

private void B_LGS_Click(object sender, RoutedEventArgs e)

        {                

            // prepare vector and matrix

            int M = LV_PagesURLs.Items.Count;
            int N = 3;

            if (M < 3) { MessageBox.Show('At least 3 domains and authority values are needed to solve the linear equation.'); return; }

            double[,] A = new double[N, M];
            double[]  b = new double[M];
         
            for ( int i = 0; i < M; i++ )
            
            {

                ListViewItem     LVI = (ListViewItem)LV_PagesURLs.Items[i];
                WebanalyzerURI   URI = (WebanalyzerURI)LVI.Content;

                int FWDLinkAmount   = WebAnalyzerFacade.Webcrawler.get_forwarddomainamount_of(URI.AbsoluteURI);
                int BACKLinkAmount  = WebAnalyzerFacade.Webcrawler.get_backdomainamount_of(URI.AbsoluteURI);
                int DBLLinkAmount   = WebAnalyzerFacade.Webcrawler.get_doubledomainamount_of(URI.AbsoluteURI);

                A[0, i] = FWDLinkAmount;
                A[1, i] = BACKLinkAmount;
                A[2, i] = DBLLinkAmount;
                
                b[i] = URI.Auth;
            
            }

            // solve the linear equation

            /*WebanalyzerWPF.NumericsFacade NumericFacilities = new WebanalyzerWPF.NumericsFacade();
            NumericFacilities.solve_Ax_Equals_b(A, b);*/

            Numerics.SolveOverdeterminedEquationSystem_DGELS(M, N, A, b);       

The fortran routine itself look like this, note that I have deleted some of the code to localize the problem:

SUBROUTINE SolveOverdeterminedEquationSystem_DGELS( M, N, A, b) ASSEMBLY_INTERFACE(NAME='SolveOverdeterminedEquationSystem_DGELS')

CHARACTER           TRANS
INTEGER             INFO, LDA, LDB, LWORK, M, N, NRHS, MN
DOUBLE PRECISION    A(:,:), b(:)

DOUBLE PRECISION, ALLOCATABLE:: WORK(:)
   
    

END SUBROUTINE

I often (but now always) get the following error(exception) when calling the fortran function:

CallbackOnCollectedDelegate has been recognized For the delegate of type 'ftn95lib.mdl!Salford.Fortran.RTLibrary+clearwin_callback::Invoke' a callback has been performed.....

Note that I had to translate the error message from german in english. Apparently the garbage collector removes something used by the fortran routine. But I can't figure out what I have done wrong.

I use VS2008 and Silverfrost FTN95 for Microsoft Visual Studio .NET 2.0.0.0 under vista.

Any help appreciated!

25 Sep 2009 8:26 #5030

If the problem could be that something is not persisting long enough then try using /SAVE on the FTN95 command line.

This is not a fix but if it solves the problem then you could use /SAVE selectively until you locate the problem.

25 Sep 2009 8:50 #5031

I tried the /save compiler option, but without success.

Someone has another idea?

The problem seems to be that the 'clearwin_callback' function gets first removed from the managed heap and the unmanaged code tries to jump to it after removal.

I don't know where the clearwin_callback comes from, maybe from the stub?

Regards

R4DIUM

25 Sep 2009 9:07 #5032

If you search through the assembly code using the Microsoft ildasm utility then you may be able to find out where the callback is being invoked.

25 Sep 2009 10:13 #5033

The only function which gets called is the DisplayPersonalBanner(). In the Stack trace this is also the function in which I am, when the error gets displayed. Do you know if this method uses the clearwin_callback?

If I force the banner to be displayed before this method gets called by calling another dummy fortran method the error does not occur. There might be something wrong with the banner function under certain circumstances!?

Still no solution.....

.custom instance void [ftn95lib]Salford.Fortran.SalfordArgumentInfoAttribute::.ctor(string) = ( 01 00 07 41 41 41 41 78 78 78 00 00 ) // ...AAAAxxx.. // Code size 303 (0x12f) .maxstack 12 .locals ([0] int32 _A_size_1, [1] int32 _A_size_2, [2] int32 _B_size_1, [3] int32 _WORK_size_1, [4] int32 WORK_start_1) IL_0000: nop IL_0001: call void [ftn95lib]Salford.Fortran.RTLibraryDisplayPersonalBanner() IL_0006: ldarg _a_extent_1 IL_000a: nop IL_000b: nop IL_000c: ldc.i4.m1 IL_000d: add IL_000e: dup IL_000f: ldc.i4.0 IL_0010: bge IL_0017 IL_0015: pop IL_0016: ldc.i4.m1 IL_0017: stloc.s _A_size_1 IL_0019: ldarg _a_extent_2 IL_001d: nop IL_001e: nop IL_001f: ldc.i4.m1 IL_0020: add IL_0021: dup IL_0022: ldc.i4.0 IL_0023: bge IL_002a IL_0028: pop IL_0029: ldc.i4.m1 IL_002a: stloc.s _A_size_2 IL_002c: ldarg _b_extent_1 IL_0030: nop IL_0031: nop IL_0032: ldc.i4.m1 IL_0033: add IL_0034: dup IL_0035: ldc.i4.0 IL_0036: bge IL_003d IL_003b: pop IL_003c: ldc.i4.m1 IL_003d: stloc.s _B_size_1 IL_003f: ldsflda valuetype [ftn95lib]Salford.Fortran.Character Numerics'SOLVEOVERDETERMINEDEQUATIONSYSTEM_DGELS#TRANS' IL_0044: ldsflda valuetype $ArrayType$4 FTN95.'\'N\'' IL_0049: ldc.i4 0x1 IL_004e: cpblk IL_0050: ldc.i4.1 IL_0051: stsfld int32 Numerics'SOLVEOVERDETERMINEDEQUATIONSYSTEM_DGELS#NRHS' IL_0056: ldarg.0 IL_0057: ldind.i4 IL_0058: dup IL_0059: ldc.i4.1 IL_005a: bge IL_0061 IL_005f: pop IL_0060: ldc.i4.1 IL_0061: stsfld int32 Numerics::'SOLVEOVERDETERMINEDEQUATIONSYSTEM_DGELS#LDA' IL_0066: ldarg.1 IL_0067: ldind.i4 IL_0068: dup IL_0069: ldarg.0 IL_006a: ldind.i4 IL_006b: bge IL_0073 IL_0070: pop IL_0071: ldarg.0 IL_0072: ldind.i4 IL_0073: dup IL_0074: ldc.i4.1 IL_0075: bge IL_007c IL_007a: pop IL_007b: ldc.i4.1 IL_007c: conv.r8 IL_007d: stsfld float32 Numerics::'SOLVEOVERDETERMINEDEQUATIONSYSTEM_DGELS#DB' IL_0082: ldarg.1 IL_0083: ldind.i4 IL_0084: dup IL_0085: ldarg.0 IL_0086: ldind.i4 IL_0087: ble IL_008f IL_008c: pop IL_008d: ldarg.0 IL_008e: ldind.i4 IL_008f: stsfld int32 Numerics::'SOLVEOVERDETERMINEDEQUATIONSYSTEM_DGELS#MN' IL_0094: ldc.i4.0 IL_0095: stsfld int32 Numerics::'SOLVEOVERDETERMINEDEQUATIONSYSTEM_DGELS#INFO' IL_009a: ldsfld int32 Numerics::'SOLVEOVERDETERMINEDEQUATIONSYSTEM_DGELS#MN' IL_009f: dup IL_00a0: ldsfld int32 Numerics::'SOLVEOVERDETERMINEDEQUATIONSYSTEM_DGELS#NRHS' IL_00a5: bge IL_00b0 IL_00aa: pop IL_00ab: ldsfld int32 Numerics::'SOLVEOVERDETERMINEDEQUATIONSYSTEM_DGELS#NRHS' IL_00b0: ldsfld int32 Numerics::'SOLVEOVERDETERMINEDEQUATIONSYSTEM_DGELS#MN' IL_00b5: add IL_00b6: dup IL_00b7: ldc.i4.1 IL_00b8: bge IL_00bf IL_00bd: pop IL_00be: ldc.i4.1 IL_00bf: stsfld int32 Numerics::'SOLVEOVERDETERMINEDEQUATIONSYSTEM_DGELS#LWORK' IL_00c4: ldsfld int32 Numerics::'SOLVEOVERDETERMINEDEQUATIONSYSTEM_DGELS#LWORK' IL_00c9: ldc.i4.m1 IL_00ca: add IL_00cb: dup IL_00cc: ldc.i4.0 IL_00cd: bge IL_00d4 IL_00d2: pop IL_00d3: ldc.i4.m1 IL_00d4: stloc.s _WORK_size_1 IL_00d6: ldc.i4.1 IL_00d7: stloc.s _WORK_start_1 IL_00d9: ldsfld int32 Numerics::'SOLVEOVERDETERMINEDEQUATIONSYSTEM_DGELS#LWORK' IL_00de: ldc.i4.8 IL_00df: mul IL_00e0: ldc.i4.0 IL_00e1: ldsfld float64* Numerics::'SOLVEOVERDETERMINEDEQUATIONSYSTE

Please login to reply.