Changeset 19806


Ignore:
Timestamp:
11/25/15 13:44:52 (9 years ago)
Author:
Eric.Larour
Message:

CHG: finished successful implementation of issm module. Now returns a memory buffer that
can be loaded in loadresultsfrombuffer in the solve.js routine. Struggled to figure out
the best way to return a binary memory buffer allocated on the HEAP8 module stack, not
the HEAPF64 stack!

Location:
issm/trunk-jpl/src/wrappers/Issm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/wrappers/Issm/issm.cpp

    r19793 r19806  
    66
    77extern "C" {
    8         int IssmModule(double* buffer, int buffersize, char* toolkits,char* solution,char* modelname){
     8        int IssmModule(char** poutput,int* poutputsize, double* buffer, int buffersize, char* toolkits,char* solution,char* modelname){
     9
     10                /*output variables:*/
     11                char* output=NULL;
     12                size_t size;
    913
    1014                /*Initialize exception trapping: */
     
    2428
    2529                /*Wrap up: */
    26                 femmodel->CleanUpJs();
     30                femmodel->CleanUpJs(&output,&size);
    2731
    2832                /*Delete Model: */
     
    3539                ExceptionTrapEnd();
    3640
    37                 /*Return unix success: */
    38                 return 0;
     41                /*Assign output pointers:*/
     42                *poutputsize=(int)size;
     43                *poutput=output;
     44
     45                /*Return output stream: */
     46                return 0 ;
    3947
    4048        }
  • issm/trunk-jpl/src/wrappers/Issm/issm.js

    r19793 r19806  
    66                  output is a binary buffer to be read by loadresultsfromcluster.
    77*/
     8       
     9        /*variables: */
     10        var poutput,output,poutputsize,outputsize;
     11        var dbinaryPtr,binHeap,binary,binarybuffer,nb
    812
    9         var binarybuffer=fid.rawbuffer(); //binarybuffer is now an arraybuffer
    10         var nb = fid.ptr; //size of array buffer in bytes.
     13        /*recover input buffer: */
     14        binarybuffer=fid.rawbuffer(); //binarybuffer is now an arraybuffer
     15        nb = fid.ptr; //size of array buffer in bytes.
    1116
    12         /*var dbinary=new Float64Array(binarybuffer); var nb=dbinary.length * dbinary.BYTES_PER_ELEMENT;
    13         var dbinaryPtr= Module._malloc(nb); var binHeap = new Uint8Array(Module.HEAPU8.buffer,dbinaryPtr,nb);
    14         binHeap.set(new Uint8Array(dbinary.buffer)); var binary=binHeap.byteOffset;*/
     17        /*dyanmically allocate the raw buffer onto the Module heap: */
     18        dbinaryPtr= Module._malloc(nb); binHeap = new Uint8Array(Module.HEAPU8.buffer,dbinaryPtr,nb);
     19        binHeap.set(new Uint8Array(binarybuffer)); binary=binHeap.byteOffset;
    1520
    16         var dbinaryPtr= Module._malloc(nb); var binHeap = new Uint8Array(Module.HEAPU8.buffer,dbinaryPtr,nb);
    17         binHeap.set(new Uint8Array(binarybuffer)); var binary=binHeap.byteOffset;
     21        /*allocate output pointers: */
     22        poutputsize = Module._malloc(4);
     23        poutput = Module._malloc(4);
    1824
    1925        //Declare TriMesh module:
    20         issmmodule= Module.cwrap('IssmModule','number',['number','number','string','string','string']);
     26        issmmodule= Module.cwrap('IssmModule','number',['number','number','number','number','string','string','string']);
    2127       
    2228        //Call issm:
    23         var output = issmmodule(binary, nb, toolkitstring,solutionstring,modelname);
     29        issmmodule(poutput, poutputsize,binary, nb, toolkitstring,solutionstring,modelname);
     30
     31        //recover outputs from pointers:
     32        var outputsize = Module.getValue(poutputsize,'i32');
    2433       
    25         return output;
     34        var outputptr = Module.getValue(poutput,'i32');
     35        output = Module.HEAP8.slice(outputptr, outputptr + outputsize);
     36       
     37        return [output,outputsize];
    2638}
Note: See TracChangeset for help on using the changeset viewer.