以下是一个简单的潮汐传输模型的代码,我已经将OpenMP用于并行计算:
!$OMP PARALLEL SHARED(w, u, v, nthreads, chunk) PRIVATE(i, j, tid)
do it = 1, itlast
!$OMP DO SCHEDULE(DYNAMIC, CHUNK)
do j = 2, nyw-1
do i = 2, nxw-1
w(i,j) = w(i,j) - rx*depth*(u(i,j) - u(i-1,j)) &
- ry*depth*(v(i,j) - v(i,j-1))
end do
end do
!$OMP END DO
!$OMP SINGLE
call boudary_condition(it)
!$OMP END SINGLE
!$OMP DO SCHEDULE(DYNAMIC, CHUNK)
do j = 1, nyw
jv1 = j
if (jv1 .ge. nyw-1) jv1 = nyw-1
do i = 1, nxw-1
u(i,j) = u(i,j) - rxg*(w(i+1,j) - w(i,j)) &
- constant*u(i,j)*sqrt((u(i,j)**2.) + (v(i,jv1)**2.))
end do
end do
!$OMP END DO
!$OMP DO SCHEDULE(DYNAMIC, CHUNK)
do j = 1, nyw-1
do i = 1, nxw
iu1 = i
if (iu1 .ge. nxw-1) iu1 = nxw-1
v(i,j) = v(i,j) - ryg*(w(i,j+1) - w(i,j)) &
- constant*v(i,j)*sqrt((u(iu1,j)**2.) + (v(i,j)**2.))
end do
end do
!$OMP END DO
call transport_equation(chunk)
!$OMP MASTER
mtprint = it/ntserprint
if (ntserprint*mtprint .ne. it) goto 20
call timeseries(it)
20 continue
!$OMP END MASTER
end do
!$OMP END PARALLEL
问题是我并不总是得到预期的结果。使用相同的输入文件,我应该总是得到相同的结果,但有时它会在输出文件中产生NaN。我不太明白为什么会这样。我在Windows 10上使用英特尔Visual Fortran Composer XE 2013来编译和运行可执行文件。
答案 0 :(得分:2)
您至少需要#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import MySQLdb
import feedparser
db = MySQLdb.connect(host="127.0.0.1",
user="root",
passwd="",
db="FeedStuff",
charset='UTF8')
urllistnzz =['international', 'wirtschaft', 'sport']
urllistbernerz =['kultur', 'wissen', 'leben']
cur = db.cursor()
for uri in urllistbernerz:
urlbernerz = feedparser.parse('http://www.bernerzeitung.ch/{uri}/rss.html'.format(uri=uri))
for entry in urlbernerz.entries:
insert_sql = u"""INSERT INTO articles (title, description, date, category,
link, source) VALUES ("{e.title}", "{e.description}",
"{e.published}", "{e.category}", "{e.link}", "Berner Zeitung")
""".format(e=entry)
cur.execute(insert_sql)
for uri in urllistnzz:
urlnzz = feedparser.parse('http://www.nzz.ch/{uri}.rss'.format(uri=uri) )
for entry in urlnzz.entries:
insert_sql = u"""INSERT INTO articles (title, description, date, category,
link, source) VALUES ("{e.title}", "{e.description}",
"{e.published}", "{e.category}", "{e.link}", "NZZ")
""".format(e=entry)
cur.execute(insert_sql)
db.commit()
cur.close()
db.close()
,it
和jv1
私有。
首先尝试解决这些问题,并告诉我们。