none
OpenMP syntax error RRS feed

  • Question

  • I'm trying to use openMP sections to run 2 separate pieces of code in separate threads, but I keep getting syntax errors so I was hoping someone could tell me where i might be going wrong, save me continuing to bang my head against the wall:

     

    // update synapse count, generations_per_epoch list, brain count, etc.
    template <typename TTrainer>
    inline void world<TTrainer>::update_world_info() {
    	// define iterator limit
    	vector<community<TTrainer>*>::iterator lim_iC = C->end();
    
    	bool world_synapse_count_is_ready = false;
    
    	#pragma omp parallel sections {
    		#pragma omp section 
    		{
    			size_t world_synapse_count = 0;
    			// update world synapse count
    			for (vector<community<TTrainer>*>::iterator iC = C->begin(); iC != lim_iC; iC++) {
    				world_synapse_count += (*iC)->synapses_per_brain * B_size;
    			}
    
    			// tell the 2nd thread that we have calculated the world synapse count
    			world_synapse_count_is_ready = true;
    
    			// update generations_per_epoch list
    			// function for generations_per_epoch is derived as a function of av_synapses_per_community
    			double av_synapses_per_community = (double) world_synapse_count / (double) kCommunities; // mean number of synapses per community
    			vector<size_t>::iterator igenerations_per_epoch_list = generations_per_epoch_list->begin();
    			for (iC = C->begin(); iC != lim_iC; iC++, igenerations_per_epoch_list++) {
    				double generations_per_epoch_statistical = kGenerationsPerEpochAverage * av_synapses_per_community / ((*iC)->B->size() * (*iC)->synapses_per_brain);
    				*igenerations_per_epoch_list = integise<unsigned>(generations_per_epoch_statistical);
    			}
    		}
    		#pragma omp section 
    		{
    			// while generations_per_epoch is being updated, work out some statistics
    			size_t world_brain_count = 0;
    			size_t world_neuron_count = 0;
    			// STEP 1: update statistics
    			for (vector<community<TTrainer>*>::iterator iC = C->begin(); iC != lim_iC; iC++) {
    				world_brain_count += (*iC)->B->size();
    				world_neuron_count += (*iC)->B->size() * (*iC)->N_var->size();
    			}
    
    			// wait until the 1st thread has calculated world_synapse_count
    			while (world_synapse_count == false)
    				wait(1);
    
    			// statistical information
    			av_brains_per_community = (double)world_brain_count / (double)kCommunities;
    			av_synapses_per_brain = (double)world_synapse_count / (double)world_brain_count;
    			av_hidden_neurons_per_brain = (double)world_neuron_count / (double)world_brain_count;
    			av_synapses_per_hidden_neuron = (double)av_synapses_per_brain / (double)av_hidden_neurons_per_brain;
    		}
    	}
    }
    

    The error started when I began putting in the pragma omp directives, and looks like this:

     

    1>c:\users\uqaschwa\blossom\structures\struct_world.h(738): error C2059: syntax error : '}'

    1>c:\users\uqaschwa\blossom\structures\struct_world.h(738): error C2143: syntax error : missing ';' before '}'

    1>c:\users\uqaschwa\blossom\structures\struct_world.h(738): error C2059: syntax error : '}'

     

    Tuesday, January 17, 2012 1:41 AM

Answers

  • Just a guess, try to change

    	#pragma omp parallel sections {

    to

    	#pragma omp parallel sections
    {

    Think the line with #pragma as something the could be completely ignored by the compiler.  It means without all these #pragma lines, the code should still be correct.


    Tuesday, January 17, 2012 3:03 AM