24.05.2014 Views

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 2 - Valid C Routine Source File<br />

/*<br />

* ********************************************************************<br />

* This is a main function that creates threads to execute the <strong>Fortran</strong><br />

* test subroutines.<br />

* ********************************************************************<br />

*/<br />

#include <br />

#include <br />

#include <br />

extern char *sys_errlist[];<br />

extern char *optarg;<br />

extern int optind;<br />

static char *prog_name;<br />

#define MAX_NUM_THREADS 100<br />

void *f_mt_exec(void *);<br />

void f_pre_mt_exec(void);<br />

void f_post_mt_exec(int *);<br />

void<br />

usage(void)<br />

{<br />

fprintf(stderr, "Usage: %s -t number_of_threads.\n", prog_name);<br />

exit(-1);<br />

}<br />

main(int argc, char *argv[])<br />

{<br />

int i, c, rc;<br />

int num_of_threads, n[MAX_NUM_THREADS];<br />

char *num_of_threads_p;<br />

pthread_attr_t attr;<br />

pthread_t tid[MAX_NUM_THREADS];<br />

prog_name = argv[0];<br />

while ((c = getopt(argc, argv, "t")) != EOF)<br />

{<br />

switch (c)<br />

{<br />

case ’t’:<br />

break;<br />

}<br />

default:<br />

usage();<br />

break;<br />

}<br />

argc -= optind;<br />

argv += optind;<br />

if (argc < 1)<br />

{<br />

usage();<br />

}<br />

num_of_threads_p = argv[0];<br />

if ((num_of_threads = atoi(num_of_threads_p)) == 0)<br />

{<br />

fprintf(stderr,<br />

"%s: Invalid number of threads to be created \n", prog_name,<br />

num_of_threads_p);<br />

exit(1);<br />

406 <strong>XL</strong> <strong>Fortran</strong> <strong>Enterprise</strong> <strong>Edition</strong> <strong>for</strong> <strong>AIX</strong> : User’s <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!