小编Cha*_*how的帖子

如何在OpenMP中将对象或结构定义为threadprivate?

我不知道如何将struct或object作为threadprivate,我正在做的事情会产生错误:

    struct point2d{
        int x;
        int y;
        point2d(){
            x = 0;
            y = 0;
        }
        //copy constructor
        point2d(point2d& p){
            x = p.x;
            y = p.y;
        }
    };      
Run Code Online (Sandbox Code Playgroud)

我声明一个静态结构,并尝试使它们成为threadprivate

    static  point2d myPoint;
    #pragma omp threadprivate(myPoint)
Run Code Online (Sandbox Code Playgroud)

它会生成错误:

错误C3057:'myPoint':目前不支持'threadprivate'符号的动态初始化

这是否意味着当前的openmp编译器不支持这个来构建一个struct threadprivate?或者我正在做的事情是错的.有没有其他方法来传递结构或对象?

这是我的代码的其余部分:

    void myfunc(){
        printf("myPoint at %p\n",&myPoint);
    }

    void main(){
    #pragma omp parallel
       {
           printf("myPoint at %p\n",&myPoint);
           myfunc();
       }

    }
Run Code Online (Sandbox Code Playgroud)

c++ struct private openmp

6
推荐指数
1
解决办法
2546
查看次数

OpenMP 中单节和节指令的区别

根据我的理解,我可以使用single指令做与sections仅使用添加nowait标志相同的工作

section指令相比,以下代码对我没有什么不同:

    void main(){
    #pragma omp parallel
        {
            int tid = omp_get_thread_num();
    #pragma omp single nowait
            {
                printf("Thread %d in #1 single construct.\n", tid);
            }
    #pragma omp single nowait
            {
                printf("Thread %d in #2 single construct.\n", tid);
            }
    #pragma omp single nowait
            {
                printf("Thread %d in #3 single construct.\n", tid);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

谁能给我一些在不同场景中使用sectionssingle指令的例子?

c++ parallel-processing multithreading directive openmp

5
推荐指数
1
解决办法
3589
查看次数

为什么使用owl:Restriction as own:EquivalenceClass的属性?

我刚开始学习语义Web,并对限制类有疑问.我挖了一段时间,但还没有找到任何答案..任何帮助将不胜感激!从教科书中,我看到了限定类的例子,它们都是要定义一个匿名owl:Restrictionbnode并将其bnode与属性相关联owl:equivalentClass.

例:

example:restrictionClass owl:equivalentClass [
    rdf:type owl:Restriction;
    owl:onProperty example:resProp;
    owl:someValuesFrom example:resValue.
]
Run Code Online (Sandbox Code Playgroud)

我的问题是我们可以直接定义限制类吗?喜欢:

 example:restrictionClass rdf:type owl:Restriction;
                         owl:onProperty example:resProp;
                         owl:someValuesFrom example:resValue.
Run Code Online (Sandbox Code Playgroud)

定义匿名有owl:Restriction什么好处?

semantic-web ontology sparql linked-data

4
推荐指数
1
解决办法
173
查看次数

BigQuery:使用 python BQ API 将新列添加到现有表中

相关问题:Bigquery 使用 BQ 命令行工具将列添加到表架构

我想使用 BigQuery Python API在 BigQuery 中向现有表添加新列(更新现有表的架构)。

但是我的代码似乎不起作用。

这是我的代码:

    flow = flow_from_clientsecrets('secret_key_path', scope='my_scope')
    storage = Storage('CREDENTIAL_PATH')
    credentials = storage.get()
    if credentials is None or credentials.invalid:
        credentials = tools.run_flow(flow, storage, tools.argparser.parse_args([]))
    http = httplib2.Http()
    http = credentials.authorize(http)
    bigquery_service = build('bigquery', 'v2', http=http)
    tbObject = bigquery_service.tables()
    query_body = {'schema': {'name':'new_column_name', 'type':'STRING'}}
    tbObject.update(projectId='projectId', datasetId='datasetId', tableId='tableId', body=query_body).execute()
Run Code Online (Sandbox Code Playgroud)

它返回Provided schema doesn't match existing table's schema错误。谁能给我一个可用的 Python 示例?非常感谢!

python google-bigquery

3
推荐指数
1
解决办法
5051
查看次数

在当前目录中运行expect script

我写了一个sftp expect脚本来上传和下载文件.

我把脚本文件放在一个文件夹中.并双击脚本以运行脚本以登录远程服务器,但每次我的脚本都将登录到主文件夹中的服务器而不是脚本所在的文件夹中.

#!/usr/bin/env expect
set login "username"
set addr "server.com"
set pw "mypassword"
set timeout -1
sleep 1
spawn sftp $login@$addr
expect "Password:" {send "$pw\r"}
sleep 1
interact
Run Code Online (Sandbox Code Playgroud)

例如,我把这个脚本放在/ Desktop上,如果我想从本地机器上的/ Desktop上传一些文件到我的服务器,我仍然需要进入/ Desktop并运行这个脚本,如果我只是双击执行它将从〜或/ root登录到我的服务器的脚本,无论默认目录是什么.我想从脚本所在的目录登录我的服务器.

有什么方法可以找到文件的位置吗?或者我需要执行搜索才能找到该文件?

linux shell expect

2
推荐指数
1
解决办法
2437
查看次数

我们能否从他们的限制中推断出两个阶级的关系?

我不确定我们是否可以从他们的限制中推断两个类的关系...如果我们有两个类:

owl:class1 rdfs:subClassOf [restriction1...], [restriction2...], [restriction3].

owl:class2 rdfs:subClassOf [restriction1...], [restriction2...].
Run Code Online (Sandbox Code Playgroud)

我们可以从这些知识中得出什么推论?看起来owl:class2比广泛owl:class1.我们能推断owl:class1 rdfs:subClassOf owl:class2.一下吗?

semantic-web inference owl ontology sparql

2
推荐指数
1
解决办法
52
查看次数

如何使用智能指针包装数组?

shared_ptr复制到数组:是否应该使用它?


根据这篇文章,使用smart_ptr包装数组的好方法是定义一个删除函数,并将删除函数单独传递给带有原始数组的smart_ptr.


我将重构我的代码,比如使用smart_ptr包装原始数组.这是一个例子:

原始代码:

    class MyList{
    public:
       MyList(int size = 0);
       void Resize(int size);
       ~MyList();
    private:
       int* myArray; 
       int* head_;
       size_t size_;
    }

    MyList::MyList(int size){
        myArray = new int[size]; //allocated memory when object is being created 
        head_ = list_;
        size_ = size;
    }

    void MyList::Resize(int size) {
        if (!list_) {
             delete myArray;
             size_ = 0;
        }
        myArray = new int[size];
        head_ = list_;
        size_ = size;
    }

    MyList::~MyList(){
       delete myArray;
       head …
Run Code Online (Sandbox Code Playgroud)

c++ pointers memory-management smart-pointers dynamic-memory-allocation

-1
推荐指数
1
解决办法
611
查看次数