Fortran und Laufzeitinformationen

In diesem Beispiel wird der folgende Dateiname verwendet: ' logrun.f

Code erstellen

Der Code in diesem Beispiel erforscht Funktionen, die möglicherweise nicht allgemein verwendet werden. Die Protokollierung kann dazu dienen, die Ausführung einer AE nachzuvollziehen. Um von Nutzen zu sein, muss die AE mit einer Protokollmaske registriert sein und die Protokollierung muss über nzudxdbg aktiviert sein. Um Systemprotokollierungsmeldungen in dem Fenster zu erhalten, in dem das NPS-System gestartet wurde, müssen Sie NPS mit der Option '-i' starten (z. B. 'nzstart -i'). Dies führt dazu, dass die NPS-Prozesse mit dem Terminal verbunden bleiben. Laufzeitinformationen liefern Statistiken über das NPS-System, einschließlich der Anzahl der Datenscheiben, der Anzahl der SPUs und des Ausführungsortes.

        program logRunUdtf
        call nzaeRun()
        stop
        end

        subroutine nzaeHandleRequest(handle)
        character(100) infoString
        integer infoInt, isSpu, isUdf, isUda, isUdtf
        double precision infoDouble
        infoString = "init"
        infoDouble = -1
        infoInt = -1
        isSpu = -1
        isUda = -1
        isUdf = -1
        isUdtf = -1

c       IGNORE ALL INPUT.
10      call nzaeGetNext(handle, hasNext)
        if (hasNext .eq. 1) then
            goto 10
        endif

c       OUTPUT WHERE WE ARE RUNNING.
        call nzaeSetOutputString(handle, 0, "Host or Spu?")
        call nzaeIsRunningOnSpu(handle, isSpu)
        if (isSpu .eq. 1) then
            call nzaeSetOutputString(handle, 1, "host")
        else
            call nzaeSetOutputString(handle, 1, "spu")
        endif
        call nzaeSetOutputNull(handle, 2)
        call nzaeSetOutputNull(handle, 3)
        call nzaeOutputResult(handle)

c       OUTPUT SUGGESTED MEMORY LIMIT.
        call nzaeGetSuggestedMemoryLimit(handle, infoDouble)
        call nzaeSetOutputString(handle, 0, "Memory Limit")
        call nzaeSetOutputNull(handle, 1)
        call nzaeSetOutputDouble(handle, 2, infoDouble)
        call nzaeSetOutputNull(handle, 3)
        call nzaeOutputResult(handle)

c       OUTPUT IS-USER-QUERY.
        call nzaeIsUserQuery(handle, infoInt)
        call nzaeSetOutputString(handle, 0, "User Query?")
        if (infoInt .eq. 1) then
            call nzaeSetOutputString(handle, 1, "Yes")
        else
            call nzaeSetOutputString(handle, 1, "No")
        endif
        call nzaeSetOutputNull(handle, 2)
        call nzaeSetOutputNull(handle, 3)
        call nzaeOutputResult(handle)

c       OUTPUT ADAPTER TYPE.
        call nzaeIsUdf(handle, isUdf)
        call nzaeIsUda(handle, isUda)
        call nzaeIsUdtf(handle, isUdtf)
        call nzaeSetOutputString(handle, 0, "Adapter Type")
        if (isUdf .eq. 1) then
            call nzaeSetOutputString(handle, 1, "udf")
        endif
        if (isUda .eq. 1) then
            call nzaeSetOutputString(handle, 1, "uda")
        endif
        if (isUdtf .eq. 1) then
            call nzaeSetOutputString(handle, 1, "udtf")
        endif
        call nzaeSetOutputNull(handle, 2)
        call nzaeSetOutputNull(handle, 3)
        call nzaeOutputResult(handle)

c       OUTPUT DATA SLICE ID.
        call nzaeGetDataSliceId(handle, infoInt)
        call nzaeSetOutputString(handle, 0, "Dataslice ID")
        call nzaeSetOutputNull(handle, 1)
        call nzaeSetOutputNull(handle, 2)
        call nzaeSetOutputInt32(handle, 3, infoInt)
        call nzaeOutputResult(handle)

c       OUTPUT TRANSACTION ID.
        call nzaeGetTransactionId(handle, infoString)
        call nzaeSetOutputString(handle, 0, "Transaction ID")
        call nzaeSetOutputString(handle, 1, infoString)
        call nzaeSetOutputNull(handle, 2)
        call nzaeSetOutputNull(handle, 3)

c       OUTPUT HARDWARE ID.
        call nzaeGetHardwareId(handle, infoString)
        call nzaeSetOutputString(handle, 0, "Hardware ID")
        call nzaeSetOutputString(handle, 1, infoString)
        call nzaeSetOutputNull(handle, 2)
        call nzaeSetOutputNull(handle, 3)
        call nzaeOutputResult(handle)

c       OUTPUT NUMBER OF DATASLICES.
        call nzaeGetNumberOfDataslices(handle, infoInt)
        call nzaeSetOutputString(handle, 0, "Number of Dataslices")
        call nzaeSetOutputNull(handle, 1)
        call nzaeSetOutputNull(handle, 2)
        call nzaeSetOutputInt32(handle, 3, infoInt)
        call nzaeOutputResult(handle)

c       OUTPUT NUMBER OF SPUS.
        call nzaeGetNumberOfSpus(handle, infoInt)
        call nzaeSetOutputString(handle, 0, "Number of Spus")
        call nzaeSetOutputNull(handle, 1)
        call nzaeSetOutputNull(handle, 2)
        call nzaeSetOutputInt32(handle, 3, infoInt)
        call nzaeOutputResult(handle)

c       DO SOME LOGGING.
        call nzaeLog(handle, "Here is some logging text!")
        call nzaeLog(handle, "Here is some more logging text!")

        return
        end

Kompilierung

Verwenden Sie die Standardkompilierung:

$NZ_EXPORT_DIR/ae/utilities/bin/compile_ae --language fortran --version 3 \
     --template compile logrun.f

Registrierung

Registrieren Sie das Beispiel mit den Optionen --mem und --mask. Die Option --mask aktiviert die Protokollierung für DEBUG und die Option --mem setzt die Speicherlaufzeitinformationen.

$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language fortran --version 3 \
     --template udtf --exe logrun --sig "log_run(int4)" \
     --return "table(name varchar(100), val_str varchar(100), \
     val_double double, val_int int4)" --mem 100k --mask debug

Aktiv

Before running, enable logging by running nzudxdbg:

nzudxdbg
Processing 1 spus
.
done
Processing host
done

Führen Sie die Abfrage in nzsql aus:

SELECT * FROM TABLE WITH FINAL(log_run(1));
         NAME         | VAL_STR | VAL_DOUBLE | VAL_INT
----------------------+---------+------------+---------
 Host OR Spu?         | spu     |            |
 Memory LIMIT         |         |     102400 |
 User Query?          | Yes     |            |
 Adapter Type         | udtf    |            |
 Dataslice ID         |         |            |       0
 Hardware ID          | 0       |            |
 Number of Dataslices |         |            |       4
 Number of Spus       |         |            |       1

Die NPS-Systemprotokollierung erscheint in dem Fenster, in dem das NPS-System gestartet wurde:

05-05-10 14:33:18 (dbos.18728) [d,udx ] Here is some logging text!
05-05-10 14:33:18 (dbos.18728) [d,udx ] Here is some more logging text!