Exemplo n.º 1
0
/**
 * Output the message to a file...
 */
int tvprintf(const char *format, va_list vl) {
    static char message[1024];

    vsprintf(message, format, vl);

    if( printFunction == NULL )
        printf( "%s", message );
    else {
        PyObject *arglist;
        PyObject *result;
        arglist = Py_BuildValue("(s)", message);
        result = PyEval_CallObject(printFunction,arglist);
        Py_DECREF(arglist);
        if (result == NULL) {
            // Unbind function
            registerPrintFunction(NULL);
            throwError( "The Python print function threw an exception!" );
        }
        Py_DECREF(result);
    }

    return 0;
}
int main (int argc, char ** argv)
{

    long *input, *output;
    long i, nElements;

    nElements = N_ELEMENTS;

    initialize (&argc, &argv, &numProcs, &myId);

    input = (long *) malloc (sizeof (long) * nElements);
    output = (long *) malloc (sizeof (long) * nElements);


#ifdef INPUT_ONE
    for (i = 0; i < nElements; i++)
        input [i] = i;
#else
    for (i = 0; i < nElements; i++)
        input [i] = 1;
#endif

    registerFunctions (tally_init, accum);
    registerPrintFunction (print);
    registerStoreResultFn (result_store);

#ifdef USE_MPI_SCAN
    registerDifferenceFunction (difference);
    registerMpiOpFn (wrap_accum, 1);
    genScan (input, nElements, sizeof (long));
#else
    genScanManual (input, nElements, sizeof (long), COMMUTATIVE);
#endif
    finalize ();
    return 0;
}