How to call a C sort function to sort a Java Array.

My name is David, I'm interning this summer doing some High Performance Computing work. I'm significantly out of my comfort zone here; I am primarily a network/network security geek, not a programming guy. I took one Java based class called problem solving with programming where we wrote like 3 programs in Java and did everything else in pseudocode and using a program called Alice http://www.alice.org/ to do things graphically. Learned basically no actual programming syntax. Also have done some self-taught perl, but only through one book and I didn't finish it, I only got about half way through it. So my expertise in programming are pretty much null.
That being said, I currently am tasked with having to figure out how to make JNI work... specifically at this time I am tasked with writing an array in Java, and designing a C program that can be called by means of JNI to sort the array. I have chosen to work with the Merge Sort algorithm. My method of coding is not one where I write the entire thing from scratch, I don't particularly have a need to master languages at this point, rather I just need to make them work. I am interested in learning, but time is of the essence for me right now. So thus far what I have done is take sample codes and tweak them to meet my purpose. However, I currently am unable to make things work. So I am asking for help.
I am going to paste 3 codes here, the first one will be my basic self-written instructions for JNI (Hello World Instructions), the second one will be my Java Array, and the third one will be my MergeSort function. I am not asking for you to DO my work for me by telling me how to manipulate my code, but rather I am asking for you to send me in the direction of resources that will be of some aid to me. Links, books (preferrably e-books so I don't have to go to a library), anything that you can send my direction that may help will be deeply appreciated. Thanks so much!
JNI Instructions:
/*The process for calling a C function in Java is as follows:
1)Write the Java Program name. Eg. HelloWorld.java
2)Compile it: javac HelloWorld.java
3)Create a header file: javah -jni HelloWorld
4)Create a C program eg. HelloWorld.java
5)Compile the C program creating a shared library eg. libhello.so (My specifc command is cc -m32 -I/usr/java/jdk1.7.0_05/include -I/usr/java/jdk1.7.0_05/include/linux -shared -o libhello.so -fPIC HelloWorld.c
6) Copy the library to the java.library.path, or LD_LIBRARY_PATH (in my case I have set it to /usr/local/lib.
7)Run ldconfig (/sbin/ldconfig)
8)Run the java program: java HelloWorld. */
//Writing the code:
//For the HelloWorld program:
//In java:
//You need to name a class:
class HelloWorld {
//You then need to declare a native method:
public native void displayHelloWorld();
//You now need a static initializer:
static {
//Load the library:
System.loadLibrary("hello");
/*Main function to call the native method (call the C code)*/
public static void main(String[] args) {
new HelloWorld().displayHelloWorld();
//In C:
#include <jni.h> //JNI header
#include "HelloWorld.h" //Header created by the javah -jni command parameter
#include <stdio.h> //Standard input/output header for C.
//Now we must use a portion of the code provided by the JNI header.
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIENV *env, jobject obj)
//Naming convention: Java_JavaProgramName_displayCProgramName
    printf("Hello World!\n");
    return;
}Java Array:
class JavaArray {
     private native int MergeSort(int[] arr);
     public static void main(String[] args)
         int arr[] = {7, 8, 6, 3, 1, 19, 20, 13, 27, 4};
     static
         System.loadLibrary("MergeSort");
}Hacked and pieced together crappy C Merge Sort code:
#include <jni.h>
#include <stdio.h>
#include "JavaArray.h"
JNIEXPORT jint JNICALL
Java_JavaArray_MergeSort(JNIEnv *env, jobject obj, jintArray arr[],jint low,jint mid,jint high)
   jint i,j,k,l,b[10];
l=low;
i=low;
j=mid+1;
while((l<=mid)&&(j<=high))
    if(arr[l]<=arr[j])
       b=arr[l];
l++;
else
b[i]=arr[j];
j++;
i++;
if(l>mid)
for(k=j;k<=high;k++)
b[i]=arr[k];
i++;
else
for(k=l;k<=mid;k++)
b[i]=arr[k];
i++;
for(k=low;k<=high;k++)
arr[k]=b[k];
void partition(jint arr[],jint low,jint high)
jint mid;
if(low<high)
mid=(low+high)/2;
partition(arr,low,mid);
partition(arr,mid+1,high);
sort(arr,low,mid,high);

You're doing OK so far up to here:
Java_JavaArray_MergeSort(JNIEnv *env, jobject obj, jintArray arr[],jint low,jint mid,jint high)This is not correct. It is not what was generated by javah. It would have generated this:
Java_JavaArray_MergeSort(JNIEnv *env, jobject obj, jintArray arr,jint low,jint mid,jint high)A 'jintArray' is already an array, embedded in an object. You don't have an array of them.
So you need to restore that, and the header file, the way 'javah' generated them, then adjust your code to call GetIntArrayElements() to get the elements out of 'arr' into a local int[] array, sort that, and then call ReleaseIntArrayElements() to put them back.

Similar Messages

  • How to call procedure in which one formal parameter is associative array ty

    how to call procedure in which one formal parameter is associative array type,
    pls explain with eg.

    >
    above code work fine but when i use case then it give error like
    i identifier should be declare
    & my code is as
    CASE v_array(i)
    WHEN 'A' THEN
    insert into di_ivpn_report (ID, test_name, table_name, status, entity, proposition)
    values (v_att_id, v_att_name, 'DI_'||v_array(i)||'_REPORT'||'_'||v_att_id,
    v_status, v_ent_name, v_array(i));
    WHEN 'B' THEN
    insert into di_mpls_report (ID, test_name, table_name, status, entity, proposition)
    values (v_att_id, v_att_name, 'DI_'||v_array(i)||'_REPORT'||'_'||v_att_id,
    v_status, v_ent_name, v_array(i));
    END CASE;
    >
    Then you have to use ordinary loop
    PROCEDURE insert_update_***_array (TRANID IN VARCHAR2, ATT_NAME IN VARCHAR2, ENT_NAME VARCHAR2, v_array IN ***_array)
      IS
        v_tranid VARCHAR2(1);
        v_att_name VARCHAR2(100) := ATT_NAME;
        v_ent_name VARCHAR2(100) := ENT_NAME;
        v_att_id VARCHAR2(6);
        v_ent_id NUMBER;
        v_status VARCHAR2(20) DEFAULT 'INACTIVE';
        I        NUMBER;
       BEGIN
        i := v_array.first;
        while i is not null loop
          CASE v_array(i)
          WHEN 'A' THEN
            insert into di_ivpn_report (ID, test_name, table_name, status, entity, proposition)
            values (v_att_id, v_att_name, 'DI_'||v_array(i)||'_REPORT'||'_'||v_att_id,
            v_status, v_ent_name, v_array(i));
          WHEN 'B' THEN
            insert into di_mpls_report (ID, test_name, table_name, status, entity, proposition)
            values (v_att_id, v_att_name, 'DI_'||v_array(i)||'_REPORT'||'_'||v_att_id,
            v_status, v_ent_name, v_array(i));
          END CASE;     
          i := v_array.next(i);
        end loop; 
    end;

  • How to call Custom RFC enabled Function Module in R/3 From XI

    Hi Experts,
    I want to call custom RFC enabled Function Module by sending some input parameters from XI.
    How to do this
    Thnx
    RAMS

    Hi RAMS,
    1. Under the SWCV Go to the Imported Objects.
    2. Right click on the RFC and click on the Import of SAP object.
    3. Give the logon server name, system number the user name and pasword.
    4. Select the RFC u want to import.
    5. Execute the import and the RFC is imported under the SWCV.
    Now u can use this Imported RFC in the scenarios of that SWCV.
    Regards
    Santhosh
    Remember to set the thread to solved when you have received a solution

  • How to call plsql procedure or function and getting back the string?

    Hi Everyone,
    i am using Jdev 11.1.1.5.0.
    i have a requirement to call plsql procedure or function from my backing bean java file and get back the returned value from the procedure or function.
    what piece of simple code i need to write in my backing bean?
    please suggest.
    Thanks.

    As always you write the method to call he pl/sql in the application module, expose this method to the client (so you see it in the datacontroll) then create a operation binding to the method and call this operation from the bean. The result you get by operation.getResult();
    You should never call pl/sql from the bean directly!
    The doc shows how to call the procedure from an application module: http://docs.oracle.com/cd/E21764_01/web.1111/b31974/bcadvgen.htm#sm0297
    Timo

  • How to call a remote capable function module?

    Hi all,
    I want to call a bapi from a R/3 that is not available in the current system were i have my WebDynpro Abap application.
    So, i called the wizard "Service Call".
    In the Select Service step i have to input the destination and Function Module and
    Before i specified an RFC destination .
    The wizard cannot find the function.
    I read the Note:
    The function module must exist in the current system! The wizard does not support to call a remote capable function module that does not exist in the current system.
    The question is :
    How can i call remote capable function module?
    Thanks,
    Ari

    Hi,
    this link might help you : <a href="http://help.sap.com/saphelp_erp2005vp/helpdata/en/22/0424ba488911d189490000e829fbbd/frameset.htm">rfc in abap</a>
    grtz
    Koen

  • How to call operating system(windows) functions like sutdown,refresh,et

    Hello,
    I am new in Oracle D2k.I want to know that how to call windows XP/7 shell commands(operating system functions) or windows function key(like F5 for system refresh in windows xp/7) in an Oracle Form.
    Actually I have to make a trigger which can fire at pressing a particular key and execute appropriate action of Windows7 like shutdown,F5(function key of windows to system refresh).
    thank you
    regards
    aaditya.

    Just for future reference, regardless if you are posting in the Forms area of the forum or any other, terms like Forms 11g, Oracle 11g, etc are parts of product names. They are not version numbers although they do offer a slight hint. It is very important that when posting you include the complete version number of any products related to the problem or question you have. For example, you said you are using Oracle Forms 11g. Look at how many possible versions "Forms 11g" could possibly be:
    11.1.1.1
    11.1.1.2
    11.1.1.3
    11.1.1.4
    11.1.1.6
    11.1.2.0
    11.1.2.1
    With each new patch release and major release, a large number of bug fixes are included. In the case of new major releases, in addition to bug fixes, many new features are added. So knowing the version number is important.
    Beyond that, it would appear that you have many questions:
    1. How to copy and paste
    2. How to execute a system shutdown
    3. How to force the browser into full screen mode
    4. Refresh - this one is unclear. What do you mean by "refresh"?
    Let me answer those that I can:
    <blockquote>o Functions like cut/copy/paste are available directly from your Forms code. For these I would recommend referring to the Builder's Online Help. Look for CUT_REGION, COPY_REGION, PASTE_REGION. It might also be helpful to understand SELECT_ALL. For example you may want to code a Copy button like this:
    GO_ITEM('some_text_field);
    SELECT_ALL;
    COPY_REGION;o To execute a system shutdown on the client machine, you would first need to WebUtil enable your form. Refer to the Forms Builder Online Help for information about how to use WebUtil. You can also find lots of information in this forum about WebUtil. Once enabled, you can execute a Windows shutdown in various ways. Here one option:
    Declare
         my_cmd varchar2(255);
    Begin
         my_cmd := 'cmd /c start "" "' || '"shutdown -s -f -t 1"' || '"';
         WEBUTIL_HOST.HOST (my_cmd);
    End;Refer to the Microsoft documentation for more information: http://technet.microsoft.com/en-us/library/bb491003.aspx
    o I'm not sure what you are attempting to do with the F11. I understand that this function key sets the browser to full screen, but the form will not exactly adjust for this change in browser size. You can adjust the applet size dynamically, but not the form. For that you would need to code the behavior yourself. So, before I can offer something specific, it would be helpful to understand what you expectation is and if what you want is to set the browser to full screen, why not just allow the end user to do it? You could easily have a java script popup displayed before the form starts which might say something like "To maximize your browser, press F11"
    o Finally, "refresh". I don't know what you mean here. Refresh what? The Windows desktop, browser, Oracle Forms.....
    </blockquote>

  • How to call more then one Function modules at the same time

    HI ,
    How to call more then one FM at the same time .
    Modertor Message: Interview-type Questions are not allowed.
    Edited by: kishan P on Jan 2, 2012 2:22 PM

    They are a few different models of the MacBook Pro ranging from 15.4" i7's to 17" i7's. I would use the same models together though when imaging them just like I do with PC's. For example I would Ghost 5 Lenovo T420 Thinkpads at the same time which all share the same exact specs and config. Looking to do the same with the MBP. I have .dmg image of OSX 10.8.1 on a firewire drive which I'm using. I image all my MBP's with this drive, the only downside is I have to do each MBP one at a time.
    Thanks

  • How to Call Webservices in ABAP(Syntax) created in abap ,java etc

    All Champs,
       Can some one explain me(programatically) that how to access webservices in following cases.
    case 1: A webservice created in ABAP (FM,BAPI,FUNCTION GROUP) by using wizard . How to call this webservice in report or in any bsp or webdynpro application.
    case 2: A webservice created in JAVA,.NET  or in any third party technology , how to use in abap(by considering that endpoint has been created for third party webservice)
    points will be rewarded .
    regards
    panky

    Hi,
    case 1: for WDP, you can create the web service model via "Import Adaptive Web Service" or "Import Web Service Model (deprecated)" by supplying wsdl URL.
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/wdjava/faq%2b-%2bmodels%2b-%2badaptive%2bweb%2bservice
    case 2: In ABAP, create a proxy object at trx code SE80.
    http://help.sap.com/saphelp_nw04s/helpdata/en/bf/d005244e9d1d4d92b2fe7935556b4c/frameset.htm
    Both cases are wizard-based. It's pretty intuitive.
    - julius

  • How to call legacy system screen in web dynpro for java?

    Now I'm using Netweaver CE for building BPM (Business Process Management).
    In BPM system, I wana call legacy system screen(ERP, C/S , Web, etc..) in web dynpro.
    I'v already known how to call legacy system method and data.( using RMI, SOAP and RFC )
    But I don't konw how to call legacy system screen.
    If there is no way calling legacy system screen, I will have to build every screen using web dynpro.
    It's so terrible.
    So I think there is a way calling legacy system screen.
    It's just my opinion.
    If It can call legacy system screen in web dynpro, please let me know how to call it.
    Or, If there is no way calling legacy system, how solve I this problem?
    Thank you reading my question.

    I assume that with "legacy system screen" you mean ABAP Dynp sceens. Of cause it would be attractive to integrate into new BPM processes. However there is a conceptional issue: You could easily integrate them e.g. into a WebDypro using a URL to to the so-called WebGUI (the ITS that makes Dynp screens Web enabled).
    However the Dynp screen store all there state in the ABAP backend. This information is not available to to the process engine, e.g. to set the Task to completed or to use the data in Output Mapping.
    In fact you need a way to wrap the how UI transaction into a WebDynpro screen including data flow.

  • How to run the Oracle Triggers,Functions and Procedures from java

    Hi ,
    I want to execute the Oracle's Triggers, Functions and Procedures from java as like executing the SQL commands by using Execute statements.
    Or can we have some other option for doing this.
    Plz help me ...

    you can use CallableStatement interface of JDBC to execute any DBMS triger,stored procedure ....
    refer any of the JDBC book for extra help
    hope you got it
    Azeem Ahmed

  • How to call the C/C++ functions in Java

    Hi,
    We have well written business API functions in C/C++.We have to use the functions in our Java programme using JNI.We do not have the rights to change or modifiy the already existing C/C++ functions,but we can create any kind of proxy implementation for the existing functions and call the programme from Java.Is it possible to do that using JNI ?? .Then how we will do that??
    Kindly suggest me (examples or best tutorial links).
    Thanks and Regards
    LAL

    1. I suggest you do a google search for "wrapper jni generator".
    (If you search back through this forum you will see that lots of people have asked how to get wrappers for existing libraries. )
    2. If you have a small number of functions you want to call, then you can write a wrapper dll by hand, matching the JNI inreface requirements. The Sun website has a tutorial on JNI, including creating wrappers.

  • How to call pl/sql procedure/function from XML

    Hi,
    I have a requirement to call pl/sql function/procedure from the RTF template. How can I do this?

    Hi,
    I have got the same requirement. We need to call the store PL/SQL procedure from the XML template to generate the fixedwidth files. Could you tell me if you are able to call PL/SQL procedure from XML template?
    Thanks,
    Ram

  • How to call a RFC-enabled function module

    Hi All,
    We have 2 systems; system 1 (client 420) and system 2 (client 600).
    I just want to know that how can a RFC-enabled function module be called from one system (420) whereas the RFC-enabled functio nmodule exists in the other system (600).
    Also, as per my understanding any RFC-enabled function module is a BAPI. Please confirm.
    Please help.
    Thanks & Regards,
    Namrata

    Hi,
    RFC enabled FM can be called from anther system:
    From 420 we can call RFC FM residing in 600, through RFC destination cretaed in SM59 tcode in 420 client.In sm59, maintain the entries of destination system i.e 600.and test the connection whether it is succesful or not/ through remote logon.
    suppose in 420 client , in sm59 u have cretaed with destination DEST600 say.
    In 420, u can code as below..
    Call  'RSSDK_LOGSYS_REMOTE_CHECK' destination DEST600
    exporting
    I_QSYSTEMNAME =
    tables
    E_T_MSG =
    there exist difference between BAPI/RFC.
    BAPI always return messages / RFC doen't.
    BAPI follows ceratin naiming convetions while defineing the parameter structures ( ex BAPI_..)
    In bapi , no dialog screens can be called.
    In bapi, statements liek COmmit work/Call Transaction/Submit...shouldn't exit.
    Bapi's are implemented as FM's and are stored as methods in Business Object repository.
    another Ex for RFC
    RSAN_LOGSYS_DETERMINE
    Revert back if any issues,
    Reagrds,
    Naveen
    Edited by: Naveen Deva on Feb 18, 2009 9:54 AM

  • Help: How to call a user defined function in a data block query?

    I created a string aggregation function in the program unit, see reference:
    http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
    I now like to call the function in my data block query. I got the error: ORA-00904: 'concatenate_list' invalid identifier.
    Please help.
    Thank you in advance.
    Jimmy

    Hi,
    You can write UDFs in java in Graphical mapping to enhance your XI Graphical mapping functionality
    The steps for doing it would be:
    1. Click on Create New function Button found on Bottom left corner on your XI Mapping window.
    2. Write your java code.
    3. Run the Mapping Test as usual.
    >>The module that is given here ...where and how it is used.
    The adapters in the Adapter Framework convert XI messages to the protocols of connected external systems and the other way around. When doing so, some
    functionality might need to be added specific to a situation which is possible with the use of custom modules.
    Typical example would be validation of file content when using a File Adapter or modification of the message payload to a common content structure which is not supported by any of the standard SAP modules.
    An Adapter module is developed as an Enterprise Java Bean and is called locally by the Adapter.
    An example on modules :
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/da5675d1-0301-0010-9584-f6cb18c04805">How to develop a module for reading file name in a sender file adapter XI 3.0</a>
    Cheers,
    Chandra

  • How to call a servlets specific function from a link?

    hi all ! Im trying to call a function callled A from a link in my JSP. Im not using any buttons. How do I make this work?
    Thanks in advance.

    Hi,
    A solution to call A might include a custom JSP element. Inside the code for the
    element, you can get a reference to whatever object that "does an A", and make a call on the respective method/function/behavior. You need to extend the standard tag handler classes.
    Good luck!

Maybe you are looking for

  • To access PD Repository, why do we have to connect to the schema owner?

    Hi we use Oracle for PD repository.  In order to connect to the repository, we create odbc connection to the repository schema owner.  The question is, can we create a application schema user and provide read/write privileges to the repository and th

  • Oracle Database Migration Assistant for Unicode (DMU) is now available!

    Oracle Database Migration Assistant for Unicode (DMU) is a next-generation GUI migration tool to help you migrate your databases to the Unicode character set. It is free for customers with database support contracts. The DMU is built on the same GUI

  • Google maps in narrative report

    Hi, I'm trying to plot addresses on a google map in a report. I'm getting the addresses displayed but no map. Can anyone help? I'm not a javascript developer. I'm just trying to put this together from what I found on various websites. Thanks! Here's

  • New iPad does not display sent messages

    i set up the mail, send mial happily. but when i go to sent mail folder, it displays sent e-mails form last year, and all the wya back to 2011, but not the ones i sent this week since getting the new iPad.  anybody have any ideas?

  • Doc is not defined

    Hello, I am submitting a string of numbers delimited with commas from a form to be utilized by a JavaScript function. Here is the string of number I am submitting: 7.4%,0.1%,0.4%,9.7%,53.1%,0.5%,15.5%,4.8%,1.6%,5.7%,1.0% Here is the function: functio