小编Gan*_*ang的帖子

如何使用g ++编译openmp

我有一个关于openmp编译的问题.

如下代码:

#include <iostream> 
#include <pthread.h>
#include <omp.h>
#include <semaphore.h>
#include <stack>
using namespace std;
sem_t empty,full;
stack<int> stk;
void produce(int i)
{
    {
    sem_wait(&empty);
            cout<<"produce "<<i*i<<endl;
            stk.push(i*i);
    sem_post(&full);
    }
}
void consume1(int &x)
{
    sem_wait(&full);
            int data=stk.top();
            stk.pop();
            x=data;
    sem_post(&empty);
}
void consume2()
{
    sem_wait(&full);
            int data=stk.top();
            stk.pop();
            cout<<"consume2 "<<data<<endl;
    sem_post(&empty);
}
int main()
{
    sem_init(&empty,0,1);
    sem_init(&full,0,0);
    pthread_t t1,t2,t3;
    omp_set_num_threads(3);
    int TID=0;
    #pragma omp parallel private(TID)
    {
            TID=omp_get_thread_num();
            if(TID==0)
            {
            cout<<"There are "<<omp_get_num_threads()<<" threads"<<endl;
            for(int i=0;i<5;i++)
                    produce(i);
            }
            else …
Run Code Online (Sandbox Code Playgroud)

c++ compilation g++ openmp

20
推荐指数
2
解决办法
7万
查看次数

如何编译推力和c ++项目?

当我想同时使用推力和c ++时,我遇到了关于编译的大问题.

这是项目结构(只是一个测试项目):

sortbase.h

#include<iostream>
#include <thrust/device_vector.h>
using namespace std;

template<class T>
class SortBase
{
public:
        void Init()
        {
        }
        void resize(const int &x)
        {
                CV.resize(x);
                cout<<"resize succeed!"<<endl;
        }
private: 
        thrust::device_vector<T> CV;
};
Run Code Online (Sandbox Code Playgroud)

sorter.h

#ifndef __SORTER_H__
#define __SORTER_H__
#include <iostream>
#include <thrust/device_vector.h>
#include "sortbase.h"
using namespace std;

template<class T>
void ttest()
{cout<<"tttttttttttttttt";cout<<endl;}
        template<class KEY>
        class Sorter
        {
        public:
                Sorter():CV(NULL)
                {
                        CV=new SortBase<KEY>();
                }
                ~Sorter()
                {
                        if (CV!=NULL)
                        {
                                delete CV;
                                CV=NULL;
                        }
                }
                __host__ __device__
                virtual bool operator()(const KEY& x,const …
Run Code Online (Sandbox Code Playgroud)

c++ cuda compilation thrust

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

标签 统计

c++ ×2

compilation ×2

cuda ×1

g++ ×1

openmp ×1

thrust ×1