- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Help me , ho can covert this code to fortran :
#include <stdio.h> #include <tchar.h> #include <windows.h> #include <omp.h> //--------------------------------------------------------- #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ extern void UseTiming1(); #ifdef __cplusplus } /* extern "C" */ #endif /* __cplusplus */ struct Thread_time { double* Thread; }; class Timing { public: Timing(); ~Timing(); void StartTiming(); void StopTiming(); Thread_time GetUserSeconds() const { for (int i = 0; i < nthreads; i++){ time.Thread=double(m_userTime)/ 10000000.0; } //delete[] m_userTime; return (time); } private: __int64* GetUserTime() const; __int64* m_userTime; Thread_time time; int nthreads; }; Timing::Timing(){ #pragma omp parallel { nthreads=omp_get_num_threads(); } printf("numbzer thread = %d\n",nthreads); m_userTime=new __int64[nthreads]; time.Thread=new double[nthreads]; } Timing::~Timing(){ delete[] m_userTime; delete[] time.Thread; } __int64* Timing::GetUserTime() const { FILETIME creationTime; FILETIME exitTime; FILETIME kernelTime; FILETIME userTime; __int64 *CurTime; CurTime=new __int64[nthreads]; #pragma omp parallel for private(creationTime,exitTime,kernelTime,userTime) for (int i = 0; i < nthreads; i++){ GetThreadTimes(GetCurrentThread(), &creationTime, &exitTime, &kernelTime, &userTime); CurTime = userTime.dwHighDateTime; CurTime <<= 32; CurTime += userTime.dwLowDateTime; } return CurTime; } void Timing::StartTiming() { m_userTime = GetUserTime(); } void Timing::StopTiming() { //for (int i = 0; i < Number_Thread; i++) __int64 *curUserTime; curUserTime = GetUserTime(); for (int i = 0; i < nthreads; i++){ m_userTime = curUserTime - m_userTime; } } //--------------------------------------------------------- void Calc() { unsigned sum = 0; // #pragma omp parallel for reduction(+:sum) num_threads(2) for (int i = 0; i < 1000000; i++) { char str[1000]; for (int j = 0; j < 999; j++) str= char(((i + j) % 254) + 1); str[999] = 0; for (char c = 'a'; c <= 'z'; c++) if (strchr(str, c) != NULL) sum += 1; } printf("sum = %u\n", sum); } void UseTiming1() { Timing t; t.StartTiming(); Calc(); t.StopTiming(); for (int i = 0; i < 2; i++) printf("Thread %d Timing: %.3G seconds.\n", i,t.GetUserSeconds().Thread); }
Link Copied
0 Replies
![](/skins/images/DF2E495CEC88D713A66401CF495CD875/responsive_peak/images/icon_anonymous_message.png)
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page